Reputation: 311
In ECMAScript 2019 one can use let
to declare a new (lexical binding) variable. (Specification section 13.3.1 https://www.ecma-international.org/ecma-262/10.0/index.html#prod-LexicalDeclaration )
Why does the list of keywords not contain let
( https://www.ecma-international.org/ecma-262/10.0/index.html#prod-Keyword
also in section 11.6.2.1)?
Upvotes: 2
Views: 221
Reputation: 215029
The list of Javascript reserved words was fixed back in 2000 in the 3rd edition of the spec (page 14). For backwards compatibility it's not possible to extend this list, because that would break existing programs. However, the spec authors couldn't predict how the language will evolve back then, and which new keywords will be needed. As a result, some "newer" keywords are not reserved, unless the strict mode is used.
var let = 1; // valid in the non-strict mode
Technically this means that let
, await
, yield
etc are not "tokens" for the compiler but just identifiers, which are given special meaning only in specific syntactic positions and treated as is otherwise (again, in the non-strict mode):
function *yield() { // identifier
yield 1; // keyword
}
var let = 1; // identifier
let x = 2; // keyword
The strict mode treats "old" and "new" reserved words equally, although error messages are different ("unexpected token" vs "strict mode reserved word").
Upvotes: 4