8

Why does typeof let return 'undefined' and is not throwing an SyntaxError instead?

console.log(typeof let);

The unary typeof operator expects an expression. Am I missing something about the let statement?

Kristianmitk
  • 4,528
  • 5
  • 26
  • 46

1 Answers1

10

The typeof operator is treating let as a undeclared variable.

See more in MDN docs.

Look at this with an undeclared variable.

console.log(typeof elefromstack)

In strict mode, an error is thrown.

'use strict'
console.log(typeof let);
Kristianmitk
  • 4,528
  • 5
  • 26
  • 46
Ele
  • 33,468
  • 7
  • 37
  • 75