Skip to content Skip to sidebar Skip to footer

Javascript Comma Operator

When combining assignment with comma (something that you shouldn't do, probably), how does javascript determine which value is assigned? Consider these two snippets: function nl(x)

Solution 1:

I was confusing two things, here. The first call to 'nl' is a function call with four arguments. The second is the evaluation of the comma into one argument.

So, the answer: the value of a list of expressions separated by ',' is the value of the last expression.

Post a Comment for "Javascript Comma Operator"