Interview Q&A · JavaScript · 10 questions in this topic
JavaScript Fundamentals — JavaScript Interview Q&A
The vocabulary every JavaScript interview opens with — what the language is, how it executes, and the engine pipeline. Part of JavaScript Fundamentals · 204 questions in the JavaScript bank.
What is JavaScript?
Answer
JavaScript is a high-level, dynamically typed, interpreted (JIT-compiled) multi-paradigm language — the language of the web, now running on servers (Node.js), desktops and embedded targets via engines like V8, SpiderMonkey and JavaScriptCore.
Created by Brendan Eich in 1995 (first shipped in Netscape), it is standardized as ECMAScript (ES2024 current) with yearly releases. Its design centers on first-class functions, prototype-based objects, and an event-driven concurrency model.
Example
// JavaScript reads like the web's mother tongue const greet = (name) => `Hello, ${name}!`; console.log(greet("Interviewer")); // Hello, Interviewer!
💡 Name dynamic typing, first-class functions and the event loop in one breath — that trio frames every follow-up.
How does JavaScript code actually execute (engine pipeline)?
Answer
Source is parsed to an AST, compiled to bytecode (Ignition in V8), interpreted — then hot functions are JIT-optimized (TurboFan) with speculative assumptions, deoptimizing if reality differs. There is no manual compile step; the engine tiers up at runtime.
This is why micro-benchmarks lie (warmup matters) and why stable object shapes (hidden classes) run dramatically faster than megamorphic ones.
Key points
- 1Parse — source to AST to bytecode.
- 2Interpret — baseline execution with profiling.
- 3Optimize — JIT hot paths, deopt on violated assumptions.
Example
// same-shape objects optimize well: const p1 = { x: 1, y: 2 }; const p2 = { x: 3, y: 4 }; // same hidden class as p1
💡 Saying interpreted-then-JIT with deoptimization shows engine-level understanding.
Is JavaScript single-threaded? How does concurrency work?
Answer
The language runtime is single-threaded per realm: one call stack, one thing at a time, with concurrency through the event loop (Web Workers / worker_threads add real threads with isolated memory). Async work (timers, I/O, fetch) defers callbacks to task/microtask queues drained between stack frames.
So: no data races on shared objects by default, but long synchronous loops still freeze everything — the classic frozen-UI bug.
Example
console.log("a"); setTimeout(() => console.log("b"), 0); Promise.resolve().then(() => console.log("c")); console.log("d"); // a d c b (microtasks before macrotasks)
💡 Single-thread plus event-loop-queues is the complete concurrency model in one sentence.
What are the primitive types vs objects?
Answer
Primitives (immutable, compared by value): string, number, bigint, boolean, undefined, symbol, null. Everything else is an object (compared by reference): plain objects, arrays, functions, dates, Maps — even functions are callable objects.
typeof null === 'object' is a 1995 bug frozen by compatibility; primitives auto-box when you access methods ('hi'.length).
Key points
- 1Primitive — immutable, value-compared (7 types).
- 2Object — mutable, reference-compared.
- 3Boxing — method access on primitives wraps temporarily.
Example
let a = { v: 1 }, b = { v: 1 }; console.log(a === b); // false: different references console.log("hi".toUpperCase()); // HI: auto-boxed
What is the difference between `null` and `undefined`?
Answer
undefined means no value assigned (declared-but-unset variables, missing properties/arguments, void returns). null is an explicit empty assignment — the programmer deliberately saying nothing here. Both are falsy and ==-equal but not ===-equal.
Modern code prefers null for intentional emptiness, undefined for untouched defaults — and ?? over || to preserve 0/'' while defaulting nullish values.
Example
let x; // undefined: untouched let user = null; // null: explicitly empty console.log(x == user); // true (loose) console.log(x === user); // false (strict)
💡 Untouched vs intentional-empty is the semantic split to state.
What is type coercion (implicit vs explicit)?
Answer
Implicit coercion converts types automatically in operations ('5' + 1 → '51', '5' - 1 → 4, if ('0') is truthy). Explicit conversion uses Number(), String(), Boolean() deliberately. == coerces before comparing (the bug farm); === compares type plus value with no conversion.
Rule: always === (except deliberate nullish x == null checks), always convert explicitly at boundaries.
Key points
- 1Implicit — operator-triggered, surprising.
- 2Explicit — Number/String/Boolean, intentional.
- 3=== — no conversion, the default choice.
Example
console.log('5' + 1); // '51' (string wins +) console.log('5' - 1); // 4 (numeric context) console.log([] == false); // true (infamous coercion chain)
What is the difference between `var`, `let` and `const`?
Answer
var is function-scoped, hoisted-and-initialized (undefined), redeclareable — the legacy footgun. let is block-scoped, hoisted-but-uninitialized (temporal dead zone), reassignable. const is block-scoped like let but single-assignment (bindings immutable; object contents still mutable).
Modern code: const by default, let when rebinding, never var.
Example
if (true) { // console.log(x); // ReferenceError: temporal dead zone let x = 1; const y = [1]; y.push(2); // fine: binding fixed, contents mutable }
💡 const-default plus never-var is the modern declaration doctrine.
What is hoisting? What is the temporal dead zone?
Answer
Hoisting moves declarations (not initializations) to scope top at compile time: var arrives undefined, function declarations arrive whole, let/const arrive uninitialized — touching them before declaration throws (the temporal dead zone). Function expressions follow their variable's rules, not function rules.
TDZ errors are the engine enforcing let/const safety that var lacked.
Example
console.log(f()); // works: function declaration hoisted function f() { return 1; } // console.log(g()); // TDZ ReferenceError const g = () => 2;
How do `==` and `===` differ? What about `Object.is`?
Answer
== coerces types then compares (the surprise factory). === compares type and value strictly (the default). Object.is matches === except two edges: NaN equals NaN (true, unlike ===), and +0 differs from -0.
Default ===; Object.is for NaN/zero-sensitive math and library-grade equality.
Example
console.log(NaN === NaN); // false console.log(Object.is(NaN, NaN)); // true console.log(0 === -0); // true console.log(Object.is(0, -0)); // false
💡 Two edges (NaN, signed zero) is all Object.is adds — memorize the pair.
What are truthy and falsy values?
Answer
Falsy (exactly eight): false, 0, -0, 0n, '', null, undefined, NaN. Everything else is truthy — including '0', 'false', [], and {} (the classic surprises). if (x) tests truthiness; ?? tests nullishness (null/undefined only); explicit Boolean() documents intent.
'0' and [] being truthy is the interview trap to have ready.
Example
if ('0') { /* runs! non-empty string is truthy */ } if ([]) { /* runs! objects are always truthy */ } const name = input ?? 'anon'; // nullish only, keeps ''
Recommended resourcesAffiliate links · may earn us a commission