liveBook · Manning

Let keyword

As explained in Acing the Frontend Interview

let is a JavaScript block-scoped variable declaration form whose binding remains uninitialized until its declaration is evaluated.

Use let for a block-scoped JavaScript binding. The binding is hoisted but remains uninitialized until execution reaches its declaration, creating the Temporal Dead Zone (TDZ). section 3.1

Interview trap: access before declaration

In `function greet() { console.log(message); let message = "Hello, world!"; }`, calling `greet()` throws a `ReferenceError: Cannot access 'message' before initialization`. Unlike var, let is not initialized to undefined during hoisting. section 3.1

Explain these points when discussing let in an interview:

  • Distinguish hoisting from initialization: the binding exists, but TDZ access fails. section 3.1
  • Contrast let with var: var receives undefined before assignment, whereas let produces a ReferenceError. section 3.1
  • Recognize that removing strict mode does not change TDZ behavior; ES6 specifies it independently of strict mode. section 3.1

How Acing the Frontend Interview covers it

How deep it goes
Explains hoisting, initialization, TDZ errors, and strict-mode behavior, but does not develop refactoring trade-offs.
Examples
Uses a greet function that logs message before its let declaration and demonstrates the resulting ReferenceError.
What it assumes
Assumes basic JavaScript functions and variables while establishing execution phases, scope, hoisting, and TDZ distinctions.
What you can do after
Evaluate let-versus-var interview examples and explain why pre-declaration access throws a ReferenceError.
How it connects
Connects let with block scope, hoisting, var, const, Temporal Dead Zone, execution context, and scope.

Also explained in

Compare how 5 books explain let keyword →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.