JavaScript Interview Questions and Answers
A complete list of 744+ JavaScript interview questions and answers, organized by topic. Click any question to jump straight to its detailed answer with code examples.
7 topics 744 questions
JavaScript Fundamentals
Variables, Scope & Hoisting
- What is the difference between var, let and const?
- What is hoisting?
- What is the temporal dead zone (TDZ)?
- What is the difference between block scope and function scope?
- Can you redeclare variables in the same scope?
- Do var, let and const create properties on the global object?
- Why does var behave unexpectedly in a for loop with closures?
- Can you modify an array declared with const?
- What is lexical scope?
- What is the scope chain?
- What is variable shadowing?
- How are function declarations scoped inside blocks?
- Why can let and const be tricky in a switch statement?
- Are function expressions hoisted?
- Are class declarations hoisted?
- What is a named function expression and why use one?
- How does variable lookup work in nested functions?
- What is an accidental (implicit) global variable?
- How does strict mode change variable behavior?
- Why must a const be initialized at declaration?
- What happens when a var and a function declaration share a name?
- What is module scope?
- How does let create a new binding each loop iteration?
- Does typeof protect against the temporal dead zone?
- What is a bare block and how does it scope variables?
- Can you shadow a let variable in a nested block?
- What is the difference between lexical and dynamic scoping?
- What actually happens during hoisting (the two phases)?
- Why is var leaking out of blocks a problem?
- How do you make an object deeply immutable?
- How does an IIFE isolate scope?
- When should you use let vs const?
- Why are global variables discouraged?
Data Types & Coercion
- What are the primitive types in JavaScript?
- What is the difference between == and ===?
- What is type coercion?
- Which values are falsy in JavaScript?
- What is the difference between null and undefined?
- How do you reliably check if a value is an array?
- Why is NaN === NaN false, and how do you test for NaN?
- What is Object.is and how does it differ from ===?
- What is the difference between +0 and -0?
- What does typeof return for a function?
- What are all the possible results of typeof?
- What is autoboxing of primitives?
- What is the difference between parseInt and Number?
- What steps does == take to coerce operands?
- How does an object convert to a primitive (Symbol.toPrimitive)?
- What roles do valueOf and toString play in coercion?
- How does coercion work in template literals?
- What are the edge cases of JSON.stringify?
- Why does 0.1 + 0.2 not equal 0.3 in JavaScript?
- What is BigInt and how does it differ from Number?
- What is the nullish coalescing operator (??)?
- What is optional chaining (?.)?
- How do you compare two arrays or objects for equality?
- What are the ways to convert a string to a number?
- What does the double-bang (!!) operator do?
- What is a Symbol and what is it used for?
- How do arrays coerce to primitives?
- Which operations produce NaN?
- What is the difference between undefined and "not defined"?
- Why doesn't typeof throw on an undeclared variable?
- What does it mean that primitives are immutable?
- How does JavaScript compare strings with < and >?
- What is the difference between shallow and deep equality?
JavaScript Functions
Closures
- What is a closure?
- What are practical uses of closures?
- Can closures cause memory leaks?
- How do closures explain the classic for-loop var bug?
- How do you create private variables with closures?
- What is currying and how do closures enable it?
- What is an IIFE and why was it used?
- What is the difference between scope and a closure?
- What is the module pattern?
- How do you implement debounce with a closure?
- How does throttle differ from debounce, and how do you implement it?
- How do you write a once() function?
- How do you implement memoization with a closure?
- What is partial application and how do closures enable it?
- How do closures help event handlers keep state?
- What does this setTimeout-in-a-loop snippet print and why?
- Do closures capture a variable's value or the variable itself?
- What is lexical scoping and how does it relate to closures?
- Does each function call create a new closure?
- What is a function factory?
- Do closures capture this?
- How do closures compare to classes for encapsulation?
- What is the revealing module pattern?
- How do generators compare to closures for maintaining state?
- How do closures cause stale values in callbacks (e.g. React)?
- When is a closure's captured scope garbage collected?
- How do nested closures work?
- How do closures appear in array method callbacks?
- What bug arises when closures unexpectedly share state?
- How do closures behave across async boundaries?
- How do you build an encapsulated counter with multiple operations?
- How does an IIFE fix the var loop closure problem?
- Do closures have a performance or memory cost?
- How do you implement a singleton with a closure?
The this Keyword
- How is the value of `this` determined?
- How does `this` work in arrow functions?
- What is the difference between call, apply and bind?
- Why does `this` become undefined when passing a method as a callback?
- What does `this` refer to inside a constructor function?
- How does strict mode change `this` in a plain function call?
- What is the precedence order of the this binding rules?
- What is this inside a DOM event listener?
- How do you control this inside forEach and similar methods?
- What is method borrowing?
- How does bind enable partial application?
- Does the new operator override a bound this?
- Why is this lost when passing an object method as a callback?
- What is this inside a promise .then callback?
- How does this behave in class methods?
- What is this at the top level of a module or script?
- Why shouldn't you use an arrow function as an object method?
- What is globalThis?
- What happens to this when you destructure a method off an object?
- What is this inside a setTimeout callback?
- What is this inside a getter or setter?
- What is this inside a static method?
- What is the "const self = this" pattern?
- Why do React class components need to bind this?
- How does returning this enable method chaining?
- What is this in a regular function nested inside a method?
- What is the difference between apply and the spread operator for arguments?
- What is this inside an IIFE?
- What is this in object method shorthand?
- Can you rebind an already-bound function?
- What happens when you pass a primitive as thisArg in sloppy mode?
- Besides this, what else do arrow functions not have?
- What is this in a prototype method?
Higher-Order Functions
- What is a higher-order function?
- What is a callback function?
- How is Array.prototype.map a higher-order function?
- What does Array.prototype.filter do and why is it a HOF?
- Explain reduce as a higher-order function.
- Why do HOFs like map/filter/reduce make code more reusable?
- What is function composition?
- What is currying?
- What is partial application and how does it differ from currying?
- What is point-free (tacit) style?
- What is memoization and how do you implement it with a HOF?
- How would you implement debounce, and why is it a HOF?
- What is throttle and how does it differ from debounce?
- How do you implement a once() higher-order function?
- Why would a function return another function?
- What's the difference between synchronous and asynchronous callbacks?
- Why does ['1','2','3'].map(parseInt) not return [1, 2, 3]?
- Why does passing a method reference as a callback often lose `this`?
- How does method chaining relate to function composition?
- What does flatMap do and when is it useful?
- How do every() and some() use callbacks?
- When wiring a callback, should you use bind or an arrow wrapper?
- What are identity and constant functions and why are they useful in HOF code?
- Why do functional libraries favor "data-last" argument order?
- What is the "error-first" callback convention?
- How do you set `this` for an array HOF callback without binding?
- How do you compose asynchronous functions?
- How would you write a generic curry() helper?
- How do HOFs offer an alternative to class inheritance for sharing behavior?
- What is a tap() function and how does it help debug pipelines?
- What bug can a HOF cause by sharing mutable state across returned functions?
Function Types & Parameters
- What is the difference between a function declaration and a function expression?
- What is the difference between named and anonymous functions?
- How do arrow functions differ from regular functions?
- What is an IIFE and why use one?
- What does it mean that functions are first-class in JavaScript?
- How do default parameters work?
- When are default parameter expressions evaluated, and in what order?
- What are rest parameters?
- What is the arguments object?
- Why don't arrow functions have their own arguments object?
- What does a function's length property return?
- How is a function's name property determined?
- How does parameter destructuring work?
- What is the difference between a method and a function?
- What is method shorthand and how does it differ from a property holding a function?
- What is recursion and what does every recursive function need?
- What is a tail call, and does JavaScript optimize them?
- What is arity?
- What is a variadic function?
- Are function arguments passed by value or by reference in JavaScript?
- What happens when you call a function with fewer or more arguments than declared?
- What is the Function constructor and why avoid it?
- How is a generator function syntactically different from a normal function?
- What makes an async function a distinct function type?
- What is a constructor function and how is `new` involved?
- How does hoisting differ between function declarations and function expressions assigned to let/const?
- Can you combine default parameters, destructuring, and rest in one signature?
- How do parameters participate in closures?
- How do getter and setter functions differ from normal methods?
- Where is the name of a named function expression visible?
Generators & Iterators
- What is the iterator protocol?
- What is the iterable protocol and how does it relate to iterators?
- Which built-in types are iterable?
- What is a generator function?
- What does the yield keyword do?
- Why can you use a generator directly in for...of and spread?
- How do generators simplify making a class iterable?
- What does it mean that generators are lazy?
- How do you build an infinite sequence safely?
- What does yield* (delegation) do?
- Can yield* delegate to non-generator iterables?
- How do you pass a value back into a generator?
- What does the generator's return() method do?
- What does the generator's throw() method do?
- What happens to a return statement inside a generator?
- How can a generator model a state machine?
- When is a generator better than building an array?
- What happens to a generator when you break out of for...of early?
- Why does iterating the same generator twice yield nothing the second time?
- What is an async generator?
- What is for await...of and where can you use it?
- How does Symbol.asyncIterator differ from Symbol.iterator?
- How do generators help with memory usage?
- How do you compose generators into a processing pipeline?
- Can a generator be an arrow function?
- What are iterator helper methods?
- Why prefer a generator over hand-writing an iterator object?
- How do destructuring and spread interact with iterators?
- How do you capture the return value of a delegated generator?
- When should you avoid generators?
JavaScript Asynchronous JavaScript
Promises & async/await
- What is a Promise?
- What is async/await and how does it relate to promises?
- How do you handle errors with promises and async/await?
- What is the difference between Promise.all and Promise.allSettled?
- What do Promise.race and Promise.any do?
- How do you run async tasks in parallel vs sequentially?
- Why does an awaited promise callback run before a setTimeout?
- How do you convert a callback-based API to a promise?
- How does promise chaining work?
- What does .then return and why does it matter?
- Where should you place .catch in a chain?
- What does .finally do?
- What is an unhandled promise rejection?
- What do Promise.resolve and Promise.reject do?
- What is a thenable?
- What happens if you throw inside a .then callback?
- What happens when you return a promise from .then?
- How do you flatten nested .then callbacks?
- How do you run promises sequentially using reduce?
- How do you limit the concurrency of many async tasks?
- How do you implement retry with exponential backoff?
- What is for await...of and when do you use it?
- What is top-level await?
- How do you cancel a promise or async operation?
- Why doesn't await work inside forEach?
- How do you start async tasks in parallel but await them later?
- How do you process an array concurrently with Promise.all and map?
- What is the explicit promise construction antipattern?
- When should you use async/await vs .then chains?
- Can a promise change its state after settling?
- What does Promise.all([]) resolve to?
- How do you handle partial failures across multiple async tasks?
- What are the risks of "fire and forget" promises?
- How do you handle errors across multiple awaits?
The Event Loop
- What is the event loop?
- What is the call stack?
- What is the difference between the macrotask and microtask queues?
- What is the output order of this snippet?
- What happens if you run a long synchronous loop?
- Can microtasks starve the event loop?
- What is queueMicrotask?
- How does requestAnimationFrame fit into the event loop?
- Is setTimeout(fn, 0) really zero milliseconds?
- How does the event loop differ between Node.js and the browser?
- What is process.nextTick in Node and how does it differ from microtasks?
- What is the output order of this async/await snippet?
- When does the browser render relative to tasks and microtasks?
- How does await schedule the rest of an async function?
- What is the difference between setInterval and recursive setTimeout?
- How are chained .then callbacks ordered against each other?
- How do you yield to the event loop to keep the UI responsive?
- What are the phases of the Node.js event loop?
- What is the difference between setImmediate and setTimeout(0) in Node?
- Does the Promise executor function run synchronously?
- What happens when you await a non-promise value?
- Does asynchronous code mean JavaScript is multithreaded?
- Why is JavaScript single-threaded?
- What is the callback (task) queue?
- What is the order of nested setTimeout and promise callbacks?
- What is a microtask checkpoint?
- Trace the output of mixed sync, await, promise and setTimeout.
- How do long tasks hurt responsiveness (INP)?
- Why use requestAnimationFrame instead of setTimeout for animation?
- Why does the loop process only one macrotask per iteration?
- What is the difference between synchronous and asynchronous code?
- How do Web Workers relate to the event loop?
- How can you defer work to the next tick using the event loop?
JavaScript Objects & Prototypes
Objects & Properties
- What are the ways to create an object in JavaScript?
- What is the difference between dot and bracket notation?
- What are shorthand properties and computed property names?
- What is a property descriptor?
- What are getters and setters?
- What do Object.keys, Object.values and Object.entries return?
- What does Object.assign do?
- How does the object spread operator work?
- How do you remove a property from an object?
- How do you check if a property exists on an object?
- What does "enumerable" mean for a property?
- What does for...in iterate over, and what is its pitfall?
- What is the difference between Object.freeze, seal and preventExtensions?
- How do you deep clone an object?
- Are objects compared by value or reference?
- How does optional chaining help with nested objects?
- What does this refer to in an object method?
- What is Object.create(null) used for?
- When should you use a Map instead of an object?
- How do you list all properties including non-enumerable and symbols?
- In what order are object keys iterated?
- What is the difference between a method and a property?
- How do you control how an object converts to a string or number?
- How does JSON.stringify handle objects?
- What does the logical assignment operator ||= and ??= do with objects?
- How do you compare two objects for equality?
- What is the difference between defining a property and assigning it?
- How do you set default values when destructuring an object?
- How do you copy an object while omitting some properties?
- How do you transform or group object data?
Prototypes & the Prototype Chain
- What is a prototype in JavaScript?
- What is the difference between __proto__ and prototype?
- How does property lookup work along the prototype chain?
- What is at the end of the prototype chain?
- Why are methods defined on the prototype instead of each instance?
- How do you tell own properties from inherited ones?
- How do you get and set an object's prototype?
- How do classes relate to prototypes?
- What is property shadowing in the prototype chain?
- How does instanceof use the prototype chain?
- What is the constructor property on the prototype?
- Can you add methods to built-in prototypes, and should you?
- What is prototype pollution?
- Where do array and string methods come from?
- How do you borrow methods from a prototype?
- Do Object.keys and for...in include inherited properties?
- What is the difference between Object.create and new?
- What is "differential inheritance" / delegation?
- What happens if you change a prototype after instances exist?
- When do you use typeof vs instanceof?
- Do arrow functions have a prototype property?
- Does a long prototype chain affect performance?
- How do you mix methods from multiple sources into a prototype?
- What breaks when an object has no prototype?
- Why is Object.setPrototypeOf discouraged?
- Is prototypal inheritance better than composition?
- Can getters and setters live on a prototype?
- Why can instanceof fail across iframes or realms?
- What is the OLOO pattern?
Prototypal Inheritance
- What is prototypal inheritance?
- How do you implement inheritance with Object.create?
- How do you set up inheritance between constructor functions?
- What is the difference between classical and prototypal inheritance?
- How do you call a parent method from a child (without class)?
- How does method overriding work with prototypes?
- What are factory functions and how do they relate to inheritance?
- What are mixins?
- Does JavaScript have the diamond problem?
- Should shared state go on the prototype?
- Are static-like properties inherited?
- What is the second argument to Object.create?
- What is parasitic / functional inheritance?
- Why can iterating an inheriting object surprise you?
- How does inheritance interact with getters and setters?
- Why is composition often preferred over inheritance in JavaScript?
- How do you check an object's type through an inheritance chain?
- What does isPrototypeOf do?
- How does this behave in an inherited method?
- Can you have multiple levels of prototypal inheritance?
- What is new.target and how does it help with inheritance?
- Does JSON.stringify include inherited properties?
- Should you use classes or raw prototypes today?
- What is the cost of adding methods to instances vs the prototype?
- How does delegation in prototypes relate to event delegation?
- How do you clone an object while preserving its prototype?
The new Operator & Constructors
- What does the new operator do?
- What is a constructor function?
- What happens if you forget new on a constructor function?
- What happens when a constructor returns a value?
- What is new.target?
- How does new connect an instance to its prototype?
- What is the difference between a constructor and a factory function?
- What is this inside a constructor?
- How do you find which constructor created an object?
- What are the built-in constructors?
- What is the pitfall of the Array constructor?
- How does instanceof relate to constructors?
- Why must super() be called before this in a subclass constructor?
- How can a constructor enforce a singleton?
- Should methods go in the constructor or on the prototype?
- What happens when you use new on a bound function?
- Can you use a constructor before it is defined?
- How do you make an abstract base constructor that can't be instantiated?
- What is Reflect.construct?
- How do constructor functions call a parent constructor?
- What does typeof return for a constructor or class?
- Should constructors have side effects?
- Why prefer object literals over new Object?
- How do you enable method chaining from a constructor's methods?
- How do you make private data with a constructor function?
JavaScript Classes & OOP
Class Syntax & Methods
- What is a class in JavaScript?
- How do classes differ from constructor functions?
- What is the constructor method?
- Where do class methods live?
- What are class fields?
- What is the difference between a method and an arrow-function field?
- What is a class expression?
- Are classes hoisted?
- How do you define different kinds of methods in a class?
- How do getters and setters work in classes?
- What is a static method?
- What is this in a class method, and how can it be lost?
- When should you use a class vs an object literal?
- How do you check if an object is an instance of a class?
- How do you customize how a class instance prints?
- Why are class bodies always in strict mode?
- Can class method names be computed?
- What is the difference between a class field and assigning in the constructor?
- Can classes have private members?
- How do you call a parent method from a subclass?
- Can a class constructor return a value?
- How do you change the [object X] tag of a class?
- Can you extend an expression, not just a class name?
- How do you enable fluent method chaining in a class?
- Why do class methods passed as callbacks lose this?
- When should you avoid classes?
Inheritance with extends & super
- How does the extends keyword work?
- What does super() do in a constructor?
- How do you call a parent method with super?
- Why does using this before super() throw?
- What is method overriding?
- How does polymorphism work with classes?
- What is the default constructor in a subclass?
- Can you use super in static methods?
- How do you extend built-in classes like Array or Error?
- How do you create an abstract class?
- When should you prefer composition over class inheritance?
- Can super access parent getters and fields?
- What is the order of initialization in a class hierarchy?
- How does instanceof behave across an inheritance hierarchy?
- How do you achieve multiple inheritance with classes?
- What is this when calling super.method()?
- How do you override a getter or setter in a subclass?
- Does JavaScript have protected members?
- Can a parent method call a method overridden by the child?
- How does super behave inside an arrow function in a method?
- What does extends null do?
- What changes when refactoring a constructor function to a class?
- How does super work across multiple inheritance levels?
- How do you compose behavior by holding instances (has-a)?
Static & Private Members
- What are static members?
- When do you use a static method?
- What are static fields?
- What is this inside a static method?
- What are private fields and how do you declare them?
- What is the difference between
- Can methods be private?
- Can static members be private?
- What is a static initialization block?
- How do you check if an object has a private field (brand check)?
- Why is encapsulation with private fields valuable?
- Are private fields inherited by subclasses?
- Are static members inherited?
- Do you have to declare private fields before use?
- How do you implement a singleton with static members?
- Why use static factory methods over constructors?
- Can you have private getters and setters?
- How was privacy done before
- When should you use a static method vs a module function?
- What is the advantage of a private method over a closure helper?
- How do you create enum-like constants with static members?
- What is a common pitfall referencing static fields?
- Why does accessing a private field on the wrong object throw?
- How do you make a class's static configuration immutable?
Mixins & Composition
- What is a mixin?
- How do you implement a mixin with Object.assign?
- What is a mixin factory (subclass factory)?
- What does "favor composition over inheritance" mean?
- What is functional composition?
- What is duck typing?
- When do you use a mixin instead of inheritance?
- What happens when two mixins define the same method?
- How do mixins handle state?
- What is delegation as a composition technique?
- What are "traits" and how do they differ from mixins?
- How is composition used outside of classes?
- Can a mixin call the base class's method?
- How do you compose objects with factory functions?
- How do mixins relate to interfaces?
- What problems come from deep inheritance hierarchies?
- Why is composition easier to test than inheritance?
- What is the difference between mixing into the prototype vs each instance?
- How does the decorator/wrapper pattern relate to composition?
- What are the downsides of mixins?
- How do you give an object only the capabilities it needs?
- How does this behave inside a mixin method?
- How do you decide between inheritance, mixins, and composition?
JavaScript Arrays & Iteration
Array Methods
- What does Array.prototype.map do?
- What does Array.prototype.filter do?
- What is forEach used for and what does it return?
- How does Array.prototype.reduce work?
- What happens if you call reduce without an initial value on an empty array?
- What is reduceRight and when would you use it?
- What is the difference between some and every?
- What is the difference between find and findIndex?
- What do findLast and findLastIndex do?
- When should you use find versus indexOf?
- What does Array.prototype.flat do?
- What is flatMap and how does it differ from map then flat?
- What does Array.from do?
- Why does Array.of exist when we have the Array constructor?
- What do entries, keys, and values return on an array?
- How does method chaining work with array methods?
- How do you use reduce to build an object from an array?
- How do you group array items by a key?
- How can reduce flatten an array of arrays?
- How do you access the index inside map, filter, or forEach?
- When should you choose map over forEach?
- What are the performance tradeoffs of chaining versus a single loop?
- What happens when you chain methods on an empty array?
- How do you decide which iteration method to use?
- How can you keep long method chains readable?
- Does map produce a deep or shallow copy?
- Why are side effects inside map considered an anti-pattern?
- Why is filter().find() sometimes wasteful, and what's better?
- How do you find the maximum value with reduce?
- How do you reliably check if a value is an array?
- Why does forEach not work well with async/await?
- What is the third argument passed to array iteration callbacks?
Mutating vs Non-Mutating
- What does it mean for an array method to mutate the array?
- Which array methods mutate the original array?
- Which common array methods return a new array instead of mutating?
- What is the difference between push and concat?
- What is the difference between slice and splice?
- Does sort mutate the array?
- What is toSorted and how does it differ from sort?
- What do toReversed, toSpliced, and with do?
- Why does mutation cause bugs in shared state?
- What are the ways to copy an array?
- What is the difference between a shallow and a deep copy of an array?
- When and how do you use structuredClone for arrays?
- What are the pitfalls of JSON.parse(JSON.stringify(arr)) for deep copy?
- How do you add an item to an array immutably?
- How do you remove an item from an array immutably?
- How do you update an item at an index immutably?
- Does Object.freeze make an array fully immutable?
- What does fill do and does it mutate?
- What does copyWithin do?
- Does reverse mutate the array?
- Why doesn't const b = a create a copy of the array?
- How can passing an array to a function mutate the caller's array?
- Is the spread operator a deep or shallow copy for arrays?
- Why must you avoid mutating arrays in React state?
- How does setting arr.length mutate the array?
- What do pop and shift return, and do they mutate?
- Are concat and spread interchangeable for combining arrays?
- How do you dedupe an array, mutating versus non-mutating?
- What problem do libraries like Immer solve for arrays?
- How can you guard against accidental mutation during development?
- When should you prefer immutable updates over mutation?
Searching & Sorting
- How does indexOf work and what does it return when nothing is found?
- What is the difference between indexOf and lastIndexOf?
- When should you use includes instead of indexOf?
- Why can't indexOf find NaN, but includes can?
- What is the difference between find and filter?
- When would you use findIndex over indexOf?
- What do findLast and findLastIndex do?
- How do some and every help with searching?
- Why does sorting numbers with sort() give wrong results?
- How do you write an ascending and descending numeric comparator?
- Does sort() mutate the array? How do you sort without mutating?
- Is JavaScript's sort stable, and why does that matter?
- How do you sort an array of objects by a property?
- How do you sort by multiple keys?
- Why use localeCompare for sorting strings?
- How do you sort strings case-insensitively?
- Does reverse() mutate, and what's the immutable alternative?
- How does the second argument to indexOf and includes work?
- How do you find all indices where a condition holds?
- When is a manual binary search worthwhile over includes/indexOf?
- What happens if you sort an array with mixed types?
- How does sort handle undefined and holes?
- Why does includes return false for an object that "looks" the same?
- What are toSorted, toReversed, toSpliced, and with?
- When should you use a Set or Map instead of array searching?
- How do you remove duplicates, optionally keeping order?
- Why can repeated work inside a comparator be a performance problem?
- What does find return when nothing matches, and why be careful?
- Does array indexOf relate to string indexOf?
- How do you sort strings that contain numbers "naturally" (file2 < file10)?
- What do searching methods return on an empty array?
Array Destructuring & Spread
- What is array destructuring?
- How do you skip elements while destructuring?
- How do default values work in array destructuring?
- How do you swap two variables with destructuring?
- How do you destructure nested arrays?
- What is the rest element in array destructuring?
- What's the difference between rest and spread, since both use ...?
- How do you copy an array with spread, and what kind of copy is it?
- How do you concatenate arrays with spread?
- When would you use concat instead of spread?
- What can you spread besides arrays?
- Why is [...str] safer than str.split('') for splitting characters?
- How do you pass an array as separate arguments?
- How does a rest element differ from rest parameters?
- How do you destructure an array in a function parameter?
- How is array destructuring used in for...of loops?
- How do you swap two elements within an array?
- Can a destructuring default reference an earlier bound variable?
- What happens when you destructure null or undefined?
- What's the classic bug with spreading nested arrays?
- When is Array.from better than spread?
- How do you immutably add or remove an item using spread?
- Does the order of spread elements matter?
- Can you combine skipping, defaults, and rest in one pattern?
- How is array destructuring used to return multiple values?
- How do you dedupe an array with spread and a Set?
- Can you flatten an array of arrays with spread?
- How do you find the max or min of an array?
- How do you conventionally ignore destructured values you don't need?
- What happens when you destructure a generator or infinite iterable?
- Is destructuring swap as fast as a temp variable?
JavaScript Modern JavaScript (ES6+)
Destructuring, Spread & Rest
- What is destructuring in JavaScript?
- How does object destructuring match variables to properties?
- How do you rename a variable while destructuring an object?
- How do default values work in object destructuring?
- How do you combine renaming and a default value?
- How do you destructure nested objects?
- How do you destructure a property whose key is computed at runtime?
- How do you destructure function parameters?
- Why give a destructured parameter a default of {}?
- What does the rest pattern do in object destructuring?
- How do you create a copy of an object without a particular property?
- What does the object spread operator do?
- How do you merge two objects with spread?
- How does property precedence work when spreading and adding keys together?
- Why is object spread only a shallow copy, and why does that matter?
- What is the difference between spread and Object.assign?
- What happens to getters when you spread an object?
- What are rest parameters in a function?
- Why prefer rest parameters over the arguments object?
- How do you combine named parameters with a rest parameter?
- How do you pass an array as individual function arguments?
- How do you swap two variables without a temp variable?
- How does destructuring help with functions that return objects?
- How do nested destructuring and defaults interact when an intermediate is missing?
- What is the difference between spread and rest, since both use the ... syntax?
- Can spread be used on things other than arrays?
- How can you destructure and immediately rename a property to avoid a name clash?
- How do you destructure objects inside an array in one pattern?
- How does spread enable immutable state updates?
- Can a destructured default reference an earlier-destructured value?
- What happens when you spread null or undefined?
- Is the rest object from destructuring a deep or shallow copy?
Optional Chaining & Nullish Coalescing
- What is optional chaining?
- How does ?. work on nested property access?
- How do you optionally call a method that might not exist?
- How does optional chaining work with array/dynamic access?
- What does short-circuiting mean in optional chaining?
- What is the nullish coalescing operator ??
- What is the difference between ?? and ||?
- When is || still the right choice over ???
- What does the ??= operator do?
- What does ||= do and how does it differ from ??=?
- What does the &&= operator do?
- How do you combine ?. with ?? for a safe default?
- Why must you parenthesize ?? when mixing it with || or &&?
- Can you use optional chaining on the left side of an assignment?
- What is the danger of over-using optional chaining?
- How does ?? differ from a destructuring default?
- How do you safely call a method on a possibly-missing array?
- Does the right-hand side of ?? always evaluate?
- How does a ?. short-circuit affect the rest of a long chain?
- Why is ?? recommended for numeric defaults?
- Does optional chaining preserve the this binding in a method call?
- How do you chain multiple ?? operators?
- Can you use optional chaining with the delete operator?
- How is ??= useful for lazy initialization or caching?
- Does ?. return undefined or the actual value when the chain succeeds?
- Why is ?? safer than || when rendering values in UI?
- Does optional chaining have meaningful performance cost?
- How do you safely invoke an optional callback and provide a result default?
- Why prefer config.x ??= default over config.x = config.x ?? default?
- How do you combine dynamic key access and optional method calls in one chain?
Template Literals & Tagged Templates
- What is a template literal?
- How does ${} interpolation work?
- How do template literals handle multiline strings?
- What kinds of expressions can you embed?
- Can you nest template literals?
- What is a tagged template?
- Why does the strings array always have one more element than values?
- What does String.raw do?
- What is the .raw property on the strings array?
- How are tagged templates used for internationalization?
- How can a tagged template prevent injection?
- What's the security pitfall of plain template literals?
- Why prefer template literals over string concatenation?
- How are non-string values coerced inside a template?
- How do you include a backtick or ${ literally?
- How do tagged templates enable CSS-in-JS?
- Why does GraphQL use a gql tagged template?
- Are the strings arrays in tagged templates cached?
- How do you handle unwanted indentation in multiline templates?
- How do you add conditional content inside a template?
- How do you render a list inside a template literal?
- Do template literals support format specifiers like printf?
- What happens with an empty or whitespace ${} slot?
- Can a tagged template return something other than a string?
- How do you write a long single-line string without a literal newline?
- Can you call a function and use its result in a slot?
- When might you still want a formatting library instead of templates?
- Are template literals related to JSX?
- How do you control whitespace between interpolations?
- What are best practices for template literals?
Symbols
- What is a Symbol?
- What is the symbol description for?
- Why can't you call Symbol with new?
- How do you use a Symbol as an object key?
- Why are symbols useful for avoiding property collisions?
- Are symbol-keyed properties enumerable?
- How do you retrieve symbol keys from an object?
- What is Symbol.for and the global symbol registry?
- What does Symbol.keyFor do?
- What are well-known symbols?
- How does Symbol.iterator make an object iterable?
- What is Symbol.asyncIterator?
- How does Symbol.toPrimitive customize coercion?
- What does Symbol.toStringTag control?
- How can Symbol.hasInstance customize instanceof?
- Are symbols a way to create private properties?
- What happens to symbols in JSON.stringify?
- What does typeof return for a symbol?
- Why does implicit string conversion of a symbol throw?
- How do symbol keys behave with Object.assign and spread?
- Why use symbols for enum-like constants?
- Why is Symbol.for useful across realms or iframes?
- How do you check if a value is a symbol?
- What does Symbol.species control?
- How do you access the built-in iterator of an array via its symbol?
- Do registered symbols cause memory concerns?
- When choose symbols over class private fields?
- What is the 'default' hint in Symbol.toPrimitive?
- What are best practices for using symbols?
More ways to practice
The self-quiz is live. Get notified when mock interviews and new question packs drop.
or
Join our WhatsApp Channel