0

JS Challenge

I came across this question in JS challenge, var a = 1,x; x = ++a + ++a; x+=a; alert(x); //output is 8 I would be really thankful if anyone explains this to me.

24th Feb 2018, 8:51 PM
Abdul Basit
Abdul Basit - avatar
3 odpowiedzi
+ 2
yes. var a,x; var a=1,x; var a,x=1; all true.
24th Feb 2018, 9:12 PM
Hasan Jafarov
Hasan Jafarov - avatar
+ 1
x=++a + ++a --> x=++1 + ++(++1)=2+ ++2=2+3=5 and a=3 ×+=a // x=x+a=5+3=8
24th Feb 2018, 9:09 PM
Hasan Jafarov
Hasan Jafarov - avatar
+ 1
I didn't understand the first line var a= 1,x; Are we assigning two values to one variable a?
24th Feb 2018, 9:10 PM
Abdul Basit
Abdul Basit - avatar