liveBook · Manning

Local variable type inference

As explained in Acing the Frontend Interview

var is a JavaScript variable declaration form whose binding is function-scoped and initialized to undefined during hoisting.

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

How Acing the Frontend Interview covers it

How deep it goes
Defines function scope and hoisting, contrasts initialization behavior, and stops short of advanced implementation analysis.
Examples
Uses output-tracing questions that compare `var` with `let` and `const` before declaration.
What it assumes
Assumes basic JavaScript familiarity while building execution-context, scope, and hoisting foundations.
What you can do after
Diagnose variable-resolution questions by tracing hoisting, scope, and initialization behavior.
How it connects
Connects `var` with hoisting, execution context, function scope, block scope, `let`, `const`, and the Temporal Dead Zone.

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.