var a = {
key1: 1,
key2: 2
};
console.log(a['key1', 'key2']); // print 2
Line 2 prints value 2, I don't understand why I do not have syntax error.
var a = {
key1: 1,
key2: 2
};
console.log(a['key1', 'key2']); // print 2
Line 2 prints value 2, I don't understand why I do not have syntax error.
This code works just fine, because you are using Comma operator, so it will evaluate all the operands and return the last evaluated one.
The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand.