+ 6
Why the following code works in js but not in python?
So any explanation on why is the following happening and what's the reason behind it to not implement the same in both languages?Ty in advance! https://code.sololearn.com/WRRcQHO2xqO7/?ref=app https://code.sololearn.com/cdUhN68i2rin/?ref=app
27 Respuestas
+ 8
From this post: https://stackoverflow.com/questions/11107823/what-happens-if-i-dont-pass-a-parameter-in-a-javascript-function
We know passing parameters is "OPTIONAL" in Js.
+ 5
Js function doesnt care how many argument you're giving it to. It'll only take what it can take and ignore the rest.
Python in the otherhand is care a lot about the parameter. its like your friend that you cant recognize when he wearing a suit
+ 4
Abhay as much as i lovr javascript, javascript history feels like a joke.
some article says the entire language was done in a week, its amazing but sure raises some question. Then microsoft releasing its own JScript, the browser wars happen. Somehow es4 adopted in macromedia/adobe flash.
It might be just a fragment from the past, who knows.
+ 4
If I was to speculate... I'd guess it has to do with how Javascript implements calling bound functions, which may or may not explicitly define parameters. ECMAScript specs state bound functions must contain a special exotic arguments object in the local function scope. This may be how Javascript supported optional arguments before supporting ES6 rest(...args).
If understanding this at a deeper level truly is important to you, I'm sure you might be able to extrapolate more about the inner workings of the language starting with these links below:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
https://tc39.es/ecma262/#sec-arguments-exotic-objects
Abhay Good luck on your quest. I hope this helps. 👌
+ 3
From my point of view. JavaScript is very unclean.
Bugs hide easily. And most of the bugs in JS are because of the unexpected functionality of JS.
+ 3
Abhay Unless this question is answered by one of the few with firsthand knowledge behind the rationale of such language design decisions or the reason can be pulled from some credible archived source or provided in the specs , it's an open ended question.
At best, the answers will be based on speculation and most likely, answers will be based on a lot of wild guesses and unhelpful commentary from people who are simply less familiar or uniformed about one or both languages.
Even if you did get a definitive answer for this question, what would you do with that knowledge? Perhaps this is a distraction from the more important objectives of learning.
While there are cases where asking the why would be helpful, I don't believe there is much benefit with this one. But that's just my opinion. 😉
That said...
+ 3
Also... I recommend digging deeper into understanding how Javascript implements lexical environments, variable scopes (global, local function, block), named parameters, and undefined values for arguments that are explicitly passed in as undefined or simply omitted and therefore undefined.
This will likely get you closer to being able to infer the rationale for the language design decisions.
+ 2
def add(x):
return x
print(str(add(add(5)))) ☕🤠
+ 1
CarrieForle thks and I know that but I still can't understand why is it so!? While in languages like python it is not
+ 1
~ swim ~ so should I delete the question?
+ 1
David Carroll I get it that it's an open-ended question and I shouldn't have used Q&A for this ,didn't realise it while asking ,simply wanted to know the benefit of implementing different design in both languages,ty very much for the info tho :)
+ 1
Sanjay Kamath that's not what I asked ,I know how arguments and parameters work in python ,
+ 1
0101001101000001 see the question and script that is being used to execute the code
+ 1
Parshant Kumar either delete the comment or I will report you ✌️
+ 1
Please follow me and be my friend
+ 1
Hey coder!
Python For Absolute Beginners in Hindi: https://www.youtube.com/playlist?list=PLELOG-a7HvqJuXB0XfVpn6HV6chm1m001
0
Parshant Kumar Delete the answer or else I will report about you
- 1
Ц сц
- 2
Hello guys, please i need help in adding a small feature to my mql4 file, please help