- 1
what does the comma mean in this javascript code?
x=10; console.log(x++,++x)
3 ответов
+ 1
bizzzzzzzo EDIT: You changed the question. Now my answer below does not match.
Javascript Lesson 7.1 has only one panel that mentions how increment operators work. It turns out to be a hard concept for many.
The arguments get evaluated from left to right, and so does the increment operator syntax.
In this case, x++ gets evaluated first:
x starts as 10.
x++: Notice x is leftmost, ++ is rightmost. It means first use the x value (10) as the argument and then afterward do the ++ on the variable x.
So now the argument is 10. The variable is 11.
The next argument is
++x
The ++ is leftmost, x is rightmost. It means first do the ++, and then afterward use the x value. So first do ++ on x... 11 + 1, and then take its value, which is 12.
Now the argument is 12, as well as x is 12.
Output:
10 12
0
the comma separates the arguments you put into the console.log() function
0
so the output 10 12 , can any one explain