I was thinking about declaring vars in JS, when a doubt arose. What’s the priority of setting up two vars’ value at the same time? See:
var a = 1,
b = 1;
With this code, a is declared before b. But what about this code
var a = b = 1;
Which one does receive the value first? a or b?
It is evaluated as
Hence,
bgets the value first.Note that this differs from the first snippet: If not already in global scope,
bwill become a global variable (if it was not declared before). This would cause an error in strict mode.A formal description can be found in the specification.