The comma operator evaluates each comma-separated operand (and returns the value of the last one).
(i = 1 + 2), (j = 3 + 4);
is functionally equivalent to
i = 1 + 2;
j = 3 + 4;
Also, as far as I know, a statement, such as var, is not considered an operator, but rather part of the operand. (See https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence )
So if each operand is being separately evaluated, why, then, does
function foobar () {
var i = 3, j = 7, z;
}
create 3 variables – i, j, and z – in foobar’s scope?
I know that’s what actually happens, but I’ve been wondering for a while why it is that this actually happens. It would seem that i should be in foobar’s scope, but that j and z should end up in the global scope.
The commas used in a
varstatement are not actually comma operators.Similarly, the commas you use to separate arguments in a function call are not comma operators either.