function() { var w = new Object(), w.x = 10, y = 11; }
SyntaxError: Expected ';'
whereas,
function() { var w = new Object(), x = w, y = 11; }
produces no error and x does have w. What is wrong with the first one?
function() { var w = new Object(), w.x = 10, y = 11; }
SyntaxError: Expected ';'
whereas,
function() { var w = new Object(), x = w, y = 11; }
produces no error and x does have w. What is wrong with the first one?
The var keyword is used to declare variables.
The only things you can put in the comma-separated list following the var keyword are variable declarations.
Therefore, your first syntax is invalid - it's read as declaring three variables (w, w.x, and y).
The assignment to w.x is a statement (which assigns a value to the w property of x), not a variable declaration, so you need a semicolon to terminate the var statement.