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,160
  • 4
  • 23
  • 41

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,160
  • 4
  • 23
  • 41
Ele
  • 32,412
  • 7
  • 33
  • 72