0
JavaScript Challenge
â CHALLENGE #214 let x = 10; let y = 5; x += y -= x *= y; console.log(x); Output: -35 Why is the answer -35 and not 25? I'm a beginner in JavaScript.
3 Answers
+ 4
see the last statement x=x*y, where x's value will be 50. And the statement before it y=y-x, where y's value will be 5-50= -45. And then x =x+y, where x's value willl be 10+(-45) = 10-45 = -35. that's why answer is -35
x=x+y(y-x(x*y))
x=10+y(5-x(10*5))
-> x=10+y(5-50)
-> x=10+(-45)
-> x=10-45
-> x=-35
I hope your question is resolved
+ 3
Because these expressions are executed from right to left.
0
Thanks Guys!