- 1

what does the comma mean in this javascript code?

x=10; console.log(x++,++x)

24th Oct 2022, 4:53 PM
bizzzzzzzo
3 odpowiedzi
+ 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
25th Oct 2022, 12:39 AM
Brian
Brian - avatar
0
the comma separates the arguments you put into the console.log() function
24th Oct 2022, 4:55 PM
Lisa
Lisa - avatar
0
so the output 10 12 , can any one explain
24th Oct 2022, 5:02 PM
bizzzzzzzo