Skip to solution
easyPhone Screen

What are `let`, `const`, and `var`? What are their differences?

614 views
01

Understand the problem

Question presented to candidate: "Walk me through var, let, and const -- what does each one actually do differently in terms of scope, hoisting, and reassignment?"

What a strong answer should cover:

  • var is function-scoped (or global at the top level) and ignores block boundaries like if and for; let and const are block-scoped, confined to the nearest curly-brace block.
  • All three are hoisted, but var is initialized to undefined immediately, while let and const are hoisted into the temporal dead zone and throw ReferenceError if read before their declaration line.
  • var can be redeclared in the same scope without error; let and const throw a SyntaxError on redeclaration in the same scope.
  • let allows reassignment; const throws TypeError on any reassignment of the binding, but does not make the referenced value itself immutable -- a const array or object can still be mutated.
  • At the top level of a script (not a module), var attaches itself as a property of the global object; let and const do not.

Clarifying questions expected:

  • "Should I also cover the temporal dead zone in detail, or just the block-versus-function scope distinction?"
  • "Do you want the classic var-in-a-loop-closure example as part of this?"

Code / implementation expected: Yes -- a short, runnable snippet demonstrating hoisting, the TDZ, redeclaration rules, and reassignment rules for all three.

variablesscopees6hoisting
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interview questions. Difficulty: Easy

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every result below was actually run on Node.js v24.19.0 — the printed output is re

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSvar, let, const: hoisting, TDZ, redeclaration, and reassignment (run directly)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 18 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track