
JavaScript Interview Question Shallow vs Deep Copy
How to answer shallow versus deep copy: a shallow copy shares nested objects, a deep copy duplicates them. See spread, structuredClone and JSON pitfalls.
Tag
38 posts

How to answer shallow versus deep copy: a shallow copy shares nested objects, a deep copy duplicates them. See spread, structuredClone and JSON pitfalls.

How to answer the this keyword interview question: this is set by how a function is called, and arrows keep the outer one. See the four rules and lost this.

How to answer call, apply and bind: call and apply invoke with a chosen this, bind returns a new function. See borrowing methods and a hand-written bind.

How to answer the garbage collection question: memory is freed when values become unreachable from roots. See mark and sweep, leaks, WeakMap and WeakRef.

How to answer what a pure function is: same input gives the same output, with no side effects. See mutation traps, hidden inputs and memoization.

How to answer the microtasks question: a queue of small jobs from promises and queueMicrotask that runs to empty after each task. See tick counts and batching.

How to answer the double versus triple equals interview question: loose equality coerces, strict does not. See the rules, NaN, Object.is and null checks.

How to answer the prototypal inheritance question: objects link to objects and lookup walks the chain. See shadowing, classes, shared array traps.

How to answer the promises interview question: an object for an eventual result that settles once and chains with then. See combinators and Promise.all.

How to answer the event delegation question: one listener on a parent handles child events because they bubble. See closest, dynamic items and limits.

Write chunk from scratch in JavaScript, split arrays into fixed-size groups, handle bad sizes and short last groups, add a lazy generator and tests. Node.js 24.

Implement Array.prototype.flat from scratch in JavaScript with depth, Infinity, holes and a stack-based version for deep input, and compare it with flatMap.