DEVPREP CODEX · #11
JavaScript Interview Questions
171 curated questions graded from Foundations (Easy) to Practical Patterns (Medium) and Internals & Architecture (Hard).
TOTAL QUESTIONS
171
THEORY QUESTIONS
150
IMPLEMENTATION FOLIOS
21
FREE QUESTIONS
5 / Level
Easy Level·57 Questions Total
Foundations & Core Concepts
Q1Explain the differences between Primitive and Reference types. How are they stored in memory, and how does `typeof` differ from `instanceof`?
- Primitive Types:
undefined,null,boolean,number,string,symbol, andbigint. Stored directly in the stack memory. They are immutable and compared by value. - Reference Types: Objects, arrays, functions, maps, and sets. Stored in the heap memory; the variable in the stack holds a pointer/reference to the heap location. They are mutable and compared by reference pointer.
- typeof: An operator that returns a string representing the data type of an unevaluated operand. Best for primitives (e.g.,
typeof "hello" === "string"), but returns"object"fornull, arrays, and plain objects. - instanceof: An operator that tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object (e.g.,
arr instanceof Array === true). Only works for objects/reference types.
Q2What is Scope in JavaScript? Compare Global, Function, and Block scopes.
- Scope: Determines the accessibility (visibility) of variables within different parts of the code.
- Global Scope: Variables declared outside any function or block. Accessible from anywhere in the application.
- Function (Local) Scope: Variables declared inside a function (using
var,let, orconst). Accessible only within that function. - Block Scope: Variables declared inside a block
{}usingletorconst. They cannot be accessed outside that block.vardoes not respect block scope.
Q3Explain Hoisting and the Temporal Dead Zone (TDZ).
- Hoisting: The default behavior of the JS interpreter where variable and function declarations are moved to the top of their containing scope before code execution.
- var hoisting: Initialized with
undefined. Accessible before declaration. - let/const hoisting: Hoisted but not initialized. Accessing them before declaration throws a
ReferenceError. - Function hoisting: Full function declarations are hoisted, making them callable before their definition in the code. Function expressions are not.
- Temporal Dead Zone (TDZ): The period between block entry and variable initialization where accessing a
letorconstvariable throws aReferenceError.
Q4Compare `var`, `let`, and `const` in terms of scoping, hoisting, and re-assignment.
| Feature | var |
let |
const |
|---|---|---|---|
| Scope | Function scope | Block scope | Block scope |
| Hoisting | Yes (initialized as undefined) |
Yes (uninitialized, TDZ active) | Yes (uninitialized, TDZ active) |
| Re-assignment | Allowed | Allowed | Not Allowed |
| Redeclaration | Allowed within same scope | Not Allowed | Not Allowed |
Q5What is a Closure? Provide a short example of why it is useful.
- Closure: A function that retains access to its lexical scope (outer variables) even when the function is executed outside that scope.
- Mechanism: Created automatically when an inner function is defined inside an outer function, capturing the outer function's environment.
- Use Cases: Data privacy/encapsulation (private variables), state maintenance, currying, and memoization.
- Example:
function createCounter() { let count = 0; return () => ++count; } const counter = createCounter(); console.log(counter()); // 1 console.log(counter()); // 2
52 More Easy Questions Locked
Unlock the complete JavaScript Easy question bank
Get instant access to all 57 questions, in-depth model answers, code sandboxes, and all 27+ technologies for a single one-time payment.
Unlock All — One-time payment · Lifetime access
Browse All JavaScript Questions by Difficulty
Easy57 Questions
Core concepts, definitions, basic syntax, and first principles expected in round 1 screening.
VIEW FULL LIST
Medium57 Questions
Real-world mechanisms, state management, edge cases, performance trade-offs, and practical coding.
VIEW FULL LIST
Hard57 Questions
Deep runtime internals, memory models, distributed design, concurrency failure modes, and architectural decisions.
VIEW FULL LIST
INTERNAL LINKING & DEPENDENCIES