Perhaps this is just a silly question, but I would appreciate the following behavior:
var obj = { key : "val1", 123 : "val2" }; obj.key; // "val1" obj.123; // Syntax error: missing; before statement obj[123]; // "val2"
Why is obj.key different from obj.123 even though they were declared as the obj key.
Access to the object literal in this way obj.123 incorrect.
And the declaration of the object as follows is correct? The browsers I tested have IE9, firefox, and chrome, and it works great for everyone.
var obj = { 123 : "val1" };
source share