I receive error “SyntaxError: Unexpected token default”
while getting or setting attribute “default” on any object in Chrome (+Opera).
({}).default
Can someone explain why this happens ?
upd: everybody, plz, becareful it doesn’t make sense for FF so while testing you can miss this bug.
defaultis a keyword in JavaScript (for theswitchstatement).Using reserved words in dot property accessors is allowed in ECMAScript Fifth Edition (specifically: the syntax for the dot property accessor is
MemberExpression . IdentifierName[section 12.2.1], andIdentifierName, unlikeIdentifier, may be aReservedWord[section 7.6]), but not in ECMAScript Third Edition (where it’sMemberExpression . Identifier). Third Edition is currently the baseline all browsers support.For safety use
[]property access:or avoid using keywords as property names.