With regards to reserved words there is a small distinctions between the "Identifiers" used for the likes of variable or function names and the "Identifier Names" allowed as properties of composite data types.
For example the following will result in an illegal syntax error:
var break = true;
Uncaught SyntaxError: Unexpected token break
However the name is deemed valid as a property of an object (as of ECMAScript 5+):
var obj = {
break: true
};
console.log(obj.break);
To quote from this answer:
From the ECMAScript® 5.1 Language Specification:
Section 7.6
Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications. An
Identifier
is anIdentifierName
that is not aReservedWord
(see 7.6.1).
Syntax
Identifier :: IdentifierName but not ReservedWord
By specification, a ReservedWord
is:
Section 7.6.1
A reserved word is an
IdentifierName
that cannot be used as anIdentifier
.ReservedWord :: Keyword FutureReservedWord NullLiteral BooleanLiteral
This includes keywords, future keywords, null
, and boolean literals. The full list of keywords are in Sections 7.6.1 and literals are in Section 7.8.
The above (Section 7.6) implies that IdentifierName
s can be ReservedWord
s, and from the specification for object initializers:
Section 11.1.5
Syntax
ObjectLiteral : { } { PropertyNameAndValueList } { PropertyNameAndValueList , }
Where PropertyName
is, by specification:
PropertyName : IdentifierName StringLiteral NumericLiteral
As you can see, a PropertyName
may be an IdentifierName
, thus allowing ReservedWord
s to be PropertyName
s. That conclusively tells us that, by specification, it is allowed to have ReservedWord
s such as class
and var
as PropertyName
s unquoted just like string literals or numeric literals.
To read more, see Section 7.6 - Identifier Names and Identifiers.
Note: the syntax highlighter in this example has spotted the reserved word and still highlighted it. While the example is valid Javascript developers can get caught out by some compiler / transpiler, linter and minifier tools that argue otherwise.