+ 1

How is the output 99... I can only get 100 on paper

var x= 9; var y= x++; console.log(++x*y);

9th May 2020, 11:50 AM
✨ Doris 🍑✨
✨ Doris 🍑✨ - avatar
2 Antworten
+ 2
var y = x++; Here 'y' is assigned 9 and not 10. The value of 'x' is first assigned and then incremented. After the statement is executed, the value of x becomes 10. console.log(++x*y); Here 'x' is again incremented and becomes 11 but 'y' remains 9 so the output is 11*9 = 99.
9th May 2020, 11:58 AM
Avinesh
Avinesh - avatar
+ 3
in y only 9 is stored ,and x value is incremented later Now x is 10 but using ++x first increases x value And it is 11 now So 11*9=99
9th May 2020, 11:58 AM
Abhay
Abhay - avatar