Javascript comma operator -


When combining the assignment with comma (something you should not do, possibly), what value was assigned to Javascript is? Consider these two snippets:

  function nl (x) {document.write (x + "& lt; br>"); } Var i = 0; Nl (I + = 1, I + = 1, I + = 1, I + = 1); Nl (i);  

and:

  function nl (x) {document.write (x + "& lt; br>"); } Var i = 0; Nl ((i + = 1, i + = 1, i + = 1, i + = 1)); Nl (i);  

The first output

  1 4  

while the other output

  4 4  

What are the brackets doing here?

I was confusing two things, here, here. The first call to 'nl' is a function call with four arguments. Second, the evaluation of a comma in an argument is evaluated.

Then, answer: ',' is the value of the list of different expressions.


Comments