Interview Q&A

Interview Q&A: 🎬 The Final Review Before the Interview: JavaScript's Mental Model in One Film Scope (var/let/const) Type Coercion (==/===) Interviewer's Question Scenario-Based,

🎬 The Final Review Before the Interview: JavaScript's Mental Model in One Film

Scope (var/let/const)

Type Coercion (==/===)

Interviewer's Question

Scenario-Based, Strong Answer

The interviewer asks: 'Why does `var` sometimes leak in JavaScript, why is `0.1+0.2 !== 0.3`, why doesn't `setTimeout(fn,0)` run instantly?' This film quickly re-runs the four core mechanisms you learned.

1️⃣ Scope — `var` is function-scoped and leaks; `let`/`const` are sealed to their block. Using `var` in a loop with async code causes the classic 'all print the last value' bug.

2️⃣ Type Coercion — `==` secretly converts types, `===` does not. `0.1+0.2 !== 0.3` comes from IEEE 754's binary approximation — not a JS bug.

3️⃣ Event Loop — the Call Stack runs sync code, the Microtask Queue (Promise) ALWAYS drains before the Macrotask Queue (setTimeout). 4️⃣ Closures — a function remembers the scope it was created in; this is the foundation of the module pattern and encapsulation.

Final — a strong interview answer does NOT end with a 'what is X?' definition; it starts with a real scenario ('I saw this in a flaky production test'), explains the mechanism, then gives the FIX. Reasoning wins interviews, not memorization.

Step by Step: How to Build a Scenario-Based Interview Answer

Tie the question to a mechanism

Which topic does the question target: scope, coercion, event loop, or closures?

Start with a concrete scenario