Skip to content Skip to sidebar Skip to footer

Why `let` Isn't Specified As Reserved Keyword In The Spec

I was expecting to find both const and let as reserved keywords. I've found only const, but there's no let: Keyword:: await break case catch class const continue <

Solution 1:

let wasn’t reserved before ES6ES5 strict mode, so it can’t be treated the same as the rest of the reserved words for backwards-compatibility reasons like this:

varlet = 5;

You’ll find lots of exceptions for it in the spec for new constructs (e.g. let let = 5; is invalid).

Solution 2:

You can see the note in the referenced document:

In some contexts yield and await are given the semantics of an Identifier. See 12.1.1. In strict mode code, let and static are treated as reserved words through static semantic restrictions (see 12.1.1, 13.3.1.1, 13.7.5.1, and 14.5.1) rather than the lexical grammar.

Post a Comment for "Why `let` Isn't Specified As Reserved Keyword In The Spec"