-1

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   <---- `const` here
    debugger default delete do
    else export extends
    finally for function
    if import in instanceof
    new
    return
    superswitch
    this throw try typeof
    var void
    while with
    yield

Is let a keyword? And if not, why?

Frank C.
  • 7,758
  • 4
  • 35
  • 45
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • 1
    Look down just a notch and you'll find a note that says "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." – BoltClock Oct 15 '17 at 10:35
  • There's a note right there explaining the status of `let` – pvg Oct 15 '17 at 10:36

2 Answers2

6

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

var let = 5;

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

Ry-
  • 218,210
  • 55
  • 464
  • 476
1

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.

OmG
  • 18,337
  • 10
  • 57
  • 90