JavaScript
Core language, async, DOM, ES6+, patterns, testing & performance
Master JavaScript interview questions covering closures, prototypes, event loop, async/await, DOM manipulation, ES6+ features, design patterns, performance optimization, and testing best practices.
Fundamentals15 topics
var vs let vs const
How the three declaration keywords differ in scope, hoisting behavior, and mutability.
Hoisting Explained
Why function and variable declarations appear to be 'moved' to the top of their scope before code runs.
Type Coercion and Equality
How JavaScript automatically converts values between types, and why == and === behave differently.
Primitive vs Reference Types
The distinction between value types (numbers, strings, booleans) and reference types (objects, arrays, functions), and how it affects copying and comparison.
The Event Loop and Call Stack
How JavaScript's single-threaded call stack cooperates with the event loop, task queue, and microtask queue to handle asynchronous work.
Lexical Scope and Scope Chain
How JavaScript resolves variable names based on where code is physically written, not where it is called from.
Truthy and Falsy Values
The short, memorizable list of values JavaScript treats as false in a boolean context, and everything else.
Template Literals and Tagged Templates
Backtick strings that support multi-line text and expression interpolation, plus the tagged template function pattern.
Operator Precedence and Short-Circuit Evaluation
How JavaScript decides the order to evaluate operators, and how && / || can skip evaluating part of an expression entirely.
typeof and instanceof Operators
Two different tools for checking a value's type at runtime — one for primitives, one for constructor-based checks on objects.
NaN and Number Edge Cases
Understanding NaN's self-inequality, floating-point precision issues, and safe ways to check for numeric validity.
Switch Statements and Fall-Through
How switch statements compare values with strict equality and why forgetting break causes cases to 'fall through.'
Immediately Invoked Function Expressions Basics
A function that runs the instant it's defined, historically used to create private scope before block-scoping and modules existed.
Strict Mode Explained
The opt-in stricter variant of JavaScript that catches silent errors, disables risky features, and is the default inside ES modules and classes.
Symbol and BigInt Primitives
Two newer primitive types: Symbol for guaranteed-unique property keys, and BigInt for integers beyond Number's safe range.
Functions12 topics
Closures Explained
How an inner function retains access to variables from its enclosing scope even after that outer function has finished executing.
Higher-Order Functions
Functions that take other functions as arguments, return functions, or both — the foundation of functional-style JavaScript.
Callbacks and Callback Hell
Passing a function to be executed later, and why deeply nested callbacks became a maintainability problem promises and async/await later solved.
Arrow Functions vs Regular Functions
Syntax differences aside, arrow functions differ from regular functions in how they bind this, whether they can be constructors, and whether they have their own arguments object.
The arguments Object and Rest Parameters
The array-like arguments object available in regular functions, and the modern rest parameter syntax that replaces most of its use cases.
Function Currying and Partial Application
Transforming a multi-argument function into a sequence of single-argument functions, and pre-filling some arguments ahead of time.
Function.prototype.call, apply, and bind
Three methods for explicitly controlling what this refers to inside a function, with different argument-passing conventions.
Default Parameters
How to give function parameters fallback values that are used automatically when no argument or undefined is passed.
Pure Functions and Side Effects
Functions that always return the same output for the same input and don't modify anything outside themselves, versus functions that mutate state or perform I/O.
Function Hoisting and Declaration vs Expression
How function declarations, function expressions, and named function expressions differ in hoisting behavior and use cases.
Recursion and Stack Depth
Writing functions that call themselves to solve problems by breaking them into smaller subproblems, and the call-stack limits that come with it.
Method Chaining and Fluent Interfaces
Designing functions/methods that return the calling object (usually this) so multiple calls can be strung together in one expression.
Async12 topics
Promises Fundamentals
The Promise object representing an eventual result of an asynchronous operation, with its three states and chaining behavior.
Async/Await Syntax
Syntactic sugar over Promises that lets asynchronous code read like synchronous code, using async functions and the await keyword.
Promise.all, allSettled, race, and any
Four static Promise combinators for running multiple promises concurrently, each with different rules for how they settle.
Microtasks vs Macrotasks
The two distinct queues the event loop draws from, and why microtasks always run before the next macrotask.
The Fetch API
The modern, Promise-based browser API for making HTTP requests, replacing XMLHttpRequest for most use cases.
Error Handling in Async Code
Strategies for catching and handling errors across callbacks, promise chains, and async/await, including unhandled rejections.
setTimeout, setInterval, and Timer Precision
Scheduling delayed or repeating code execution, and why the delay argument is a minimum, not a guarantee.
Async Iterators and for-await-of
Iterating over sequences of values that arrive asynchronously, such as paginated APIs or streamed data, using async generators and for-await-of.
Debouncing and Throttling
Two techniques for limiting how often a function runs in response to rapidly repeating events, like scrolling or typing.
Promise Chaining Pitfalls
Common mistakes when chaining .then() calls, including forgetting to return, nested chains, and swallowed errors.
Node.js Event Loop Phases
How Node.js's libuv-based event loop differs from the browser's, with distinct phases for timers, I/O callbacks, and microtasks.
Web Storage vs Cookies for Async Data
How localStorage, sessionStorage, and cookies differ in capacity, lifetime, and how they interact with server requests, relevant when caching async fetch results client-side.
Objects12 topics
Prototype Chain Explained
How objects inherit properties and methods from other objects through an internal link called the prototype, forming a chain up to Object.prototype.
The this Keyword in Depth
How the value of this is determined dynamically at call time based on four binding rules, rather than lexically like a normal variable.
ES6 Classes and Inheritance
The class syntax as syntactic sugar over prototype-based inheritance, including extends, super, and static members.
Object Destructuring
Extracting properties from objects into individual variables using a concise pattern-matching syntax, including renaming, defaults, and nested patterns.
Object.freeze, seal, and Immutability Patterns
Built-in methods for restricting how much an object can be changed, and why true deep immutability requires more than a single call.
Getters and Setters
Defining object properties backed by functions that run on access or assignment, letting you compute values or add validation transparently.
Optional Chaining and Nullish Coalescing
Two ES2020 operators for safely accessing deeply nested properties and providing fallback values only for null/undefined.
Object.keys, values, entries, and Iteration
The three static methods for extracting an object's own enumerable properties as arrays, and how they interact with for...in and destructuring.
Shallow Copy vs Deep Copy
The difference between copying only an object's top level versus recursively copying every nested structure, and the tools available for each.
Map and Set vs Plain Objects and Arrays
The dedicated key-value and unique-value collection types, and why they're often better choices than objects and arrays for certain use cases.
Composition Over Inheritance
Building complex objects by combining small, focused behaviors together rather than through deep class inheritance hierarchies.
Private Class Fields and Encapsulation
The # syntax for true private fields and methods in JavaScript classes, enforced by the engine rather than by convention.
DOM10 topics
DOM Manipulation Basics
Selecting, creating, modifying, and removing elements from the live document tree using core DOM APIs.
Event Bubbling and Capturing
The two phases an event travels through the DOM tree — capturing down from the root, then bubbling back up from the target — and how to hook into either.
Event Delegation Pattern
Attaching a single event listener to a common ancestor instead of many listeners on individual children, relying on event bubbling.
preventDefault vs stopPropagation
Two distinct event methods often confused: one cancels the browser's default action for an event, the other stops the event from traveling further through the DOM.
localStorage, sessionStorage, and IndexedDB
The three main client-side storage APIs, ranging from simple synchronous key-value storage to a full asynchronous, transactional database in the browser.
The Virtual DOM Concept
The in-memory representation of the UI that frameworks like React diff against the previous version to compute minimal real DOM updates.
MutationObserver and Reacting to DOM Changes
A browser API for observing and reacting to changes in the DOM tree — added/removed nodes, attribute changes, text changes — asynchronously and efficiently.
Web Components and Custom Elements
Native browser APIs for creating reusable, encapsulated HTML elements without relying on a JavaScript framework.
Intersection Observer for Lazy Loading
An efficient, asynchronous browser API for detecting when an element enters or exits the viewport, commonly used for lazy loading and infinite scroll.
Shadow DOM and Style Encapsulation
A native browser mechanism for attaching an isolated DOM subtree to an element, preventing styles and markup from leaking in either direction.
ES6+12 topics
ES Modules: import and export
The native, standardized module system for splitting JavaScript code across files, replacing older ad-hoc patterns like CommonJS and IIFEs for the browser.
Iterators and the Iterable Protocol
The formal protocol that makes an object usable with for...of, spread syntax, and destructuring, and how to implement it on custom objects.
Generator Functions
Functions that can pause and resume execution using yield, producing values lazily one at a time and automatically implementing the iterator protocol.
Spread and Rest Operators
The three-dot syntax that expands an iterable into individual elements (spread) or collects multiple elements into a single array (rest), depending on context.
Array Destructuring
Unpacking values from arrays into individual variables by position, including skipping elements, defaults, and swapping variables.
Proxy and Reflect
Meta-programming APIs that let you intercept and customize fundamental object operations like property access, assignment, and deletion.
Well-Known Symbols and Symbol.iterator
The set of built-in Symbol values that let user code hook into and customize core language behaviors like iteration, type coercion, and instanceof checks.
Array.prototype Methods: flat, flatMap, includes
Three newer array methods that flatten nested arrays, combine mapping with flattening in one pass, and check for element presence without coercion quirks.
Tagged Template Literals for Safe HTML
Using tagged template functions to automatically escape interpolated values, a real-world defense against injection when building HTML or SQL strings dynamically.
Optional Catch Binding and Error Cause
Two smaller but useful ES additions: catching an error without naming a variable, and chaining errors together with a structured cause property.
Numeric Separators and New Number Methods
Underscore separators for readable large numeric literals, plus static Number methods that avoid relying on global functions with looser coercion.
Array.from and Array-Like Objects
Converting iterables and array-like objects (things with a length and indices but no array methods) into real arrays, optionally with a mapping function.
Patterns10 topics
Module Pattern and Revealing Module Pattern
Using closures (often via an IIFE) to create private state and expose only a deliberately chosen public API.
Singleton Pattern
Ensuring only one instance of a particular object or resource ever exists throughout an application's lifetime, with a single global access point.
Factory Pattern
Using a function or method to create and return objects, encapsulating the object-creation logic away from the calling code.
Observer Pattern and Pub/Sub
A pattern where one or more 'observers' subscribe to notifications from a 'subject,' decoupling the code that triggers events from the code that reacts to them.
Debounced Search Pattern (Practical Application)
A common, composed real-world pattern combining debouncing, async fetch cancellation, and race-condition handling for a search-as-you-type UI.
Strategy Pattern
Encapsulating interchangeable algorithms or behaviors behind a common interface so they can be swapped at runtime without changing the code that uses them.
Decorator Pattern in JavaScript
Wrapping a function or object to add extra behavior transparently, without modifying its original source code.
State Machine Pattern for UI Logic
Modeling a component's behavior as a finite set of distinct states and explicit transitions between them, instead of scattered boolean flags.
Dependency Injection in JavaScript
Passing a component's dependencies in from outside rather than having it construct or reach out for them internally, improving testability and flexibility.
Immutable Update Patterns for State Management
Conventions for updating nested objects and arrays without mutating the original, central to predictable state management in frameworks like Redux and React.
Performance8 topics
Memory Management and Garbage Collection
How JavaScript automatically allocates and reclaims memory, and the mark-and-sweep algorithm that decides what can be safely freed.
Reflow, Repaint, and Layout Thrashing
The two expensive rendering steps triggered by DOM/style changes, and the anti-pattern of alternating reads and writes that forces the browser to recalculate layout repeatedly.
Web Workers for Offloading Heavy Computation
Running JavaScript on a separate background thread to keep the main thread responsive during CPU-intensive work.
requestAnimationFrame and Smooth Animations
A browser API for scheduling visual updates in sync with the display's refresh cycle, producing smoother animations than setTimeout-based approaches.
Code Splitting and Lazy Loading Modules
Breaking a JavaScript bundle into smaller chunks loaded on demand, using dynamic import() to reduce the initial page load's JavaScript payload.
Memoization and Caching Strategies
Storing the results of expensive function calls keyed by their arguments, so repeated calls with the same input can return a cached result instantly.
Passive Event Listeners and Scroll Performance
The passive option for addEventListener that tells the browser a handler won't call preventDefault, letting scrolling proceed immediately without waiting.
Bundle Size Optimization and Tree Shaking
Techniques bundlers use to eliminate unused code from a final JavaScript bundle, relying heavily on ES modules' static import/export structure.
Testing9 topics
Unit Testing Fundamentals with Jest
The core building blocks of writing unit tests — test/describe blocks, assertions with expect, and the arrange-act-assert structure — using Jest as the representative framework.
Mocking Functions and Modules
Replacing real dependencies with controlled fake implementations during tests to isolate the code under test and verify how it interacts with its dependencies.
Test-Driven Development (TDD)
A development workflow where a failing test is written before the implementation code, following a strict red-green-refactor cycle.
Debugging with the Browser DevTools Debugger
Using breakpoints, the call stack panel, and watch expressions in browser DevTools to pause execution and inspect program state at a specific point.
Snapshot Testing
Capturing a serialized representation of a value or rendered output and comparing future test runs against that saved baseline, flagging any unexpected differences.
Testing Asynchronous Code
Techniques and common pitfalls for correctly testing promise-based and callback-based asynchronous code, including fake timers.
Code Coverage and Its Limitations
What code coverage metrics actually measure (lines/branches executed by tests), and why high coverage numbers don't guarantee genuinely good tests.
Integration Testing vs Unit Testing
The distinction between testing units in isolation with mocked dependencies versus testing how multiple real components work together, and the tradeoffs of each.
End-to-End Testing with Playwright/Cypress
Automated browser tests that simulate real user interactions through an actual, full application stack, providing the highest-confidence but slowest and most expensive layer of the testing pyramid.