The `var` declaration creates a function-scoped binding. During hoisting, the binding is initialized to `undefined`, making its behavior different from `let` and `const`, which can remain inaccessible in the Temporal Dead Zone. section 3.1
Explain these points when reasoning through an interview question:
- Trace variable resolution through the function’s execution and scope model. section 3.1
- Distinguish `var` hoisting from the `ReferenceError` produced when `let` or `const` is accessed before initialization. section 3.1
- Use scope and hoisting terminology to analyze unfamiliar code and debug runtime behavior. section 3.1
Interview output question
A typical question asks you to predict a variable’s output before its declaration. The key follow-up is whether the declaration uses `var`, `let`, or `const`, because hoisting and initialization differ. section 3.1
Table 3.1 Core concepts of execution and scope
|
Topic
|
Fundamentals
|
Applied skills
|
Advanced
|
|
Execution context & scope
|
Define global/function/block scope, explain variable hoisting.
|
Trace scope chain; explain closures.
|
Debug closure bugs, analyze memory leaks; optimize lexical scoping.
|
|
The
this keyword
|
Explain
this in functions/objects, show basic usage.
|
Use
bind,
call,
apply; handle
this in arrow functions and events.
|
Solve tricky
this bugs; manage context in frameworks; design mindful APIs.
|
|
Type coercion & equality
|
Explain == vs ===, identify truthy/falsy values.
|
Prevent coercion bugs; handle edge cases; use explicit conversions.
|
Audit coercion issues, enforce linting rules; educate teams on common pitfalls.
|
|
Error handling
|
Use
try/
catch, explain sync vs async errors.
|
Handle errors in Promises/async code; create custom error types.
|
Architect global error handling; implement error boundaries; add monitoring systems.
|
Use the execution-and-scope table to connect hoisting with global, function, and block scope and to extend the analysis toward closures. section 3.1
