Languages · 64 concepts
JavaScript
How JavaScript really runs: values, scope, this, prototypes, async and the event loop, memory, and the utilities interviews ask you to build.
Asked in these mock interviews
Part 1 · 3 concepts
Values, types and coercion
- 01
Primitives vs objects, typeof, null vs undefined
JavaScript has seven primitive types (string, number, bigint, boolean, undefined, symbol, null) that are immutable and compared by value; everything else is an object…
- 02
Numbers, precision, BigInt and string comparison
Every JavaScript number is a 64-bit floating-point value, so 0.1 + 0.2 is not exactly 0.3 and integers are only safe up to 2^53 − 1; strings are sequences of UTF-16…
- 03
Coercion, == vs === and Object.is
=== compares without converting types; == runs the Abstract Equality algorithm, which converts operands (objects go through ToPrimitive, booleans become numbers)…
Part 2 · 5 concepts
Scope, hoisting and closures
- 04
Scope, the scope chain and strict mode
Scope is decided by where code is written (lexical scope): a variable lookup starts in the current block or function and walks outward through the enclosing scopes to…
- 05
var, let and const
var is function-scoped and can be redeclared; let and const are block-scoped and have a temporal dead zone; const stops reassignment of the binding, not changes to the…
- 06
Execution context, the call stack and hoisting
Before running a scope, the engine creates an execution context and registers all its declarations: function declarations get their full body, var gets undefined, and…
- 07
Closures
A closure is a function together with the variables of the scope where it was created; the function keeps those variables (live bindings, not copies) and can read and…
- 08
Closures in real code: privacy, factories and stale values
In real code closures give you private state, factories and pre-configured callbacks, and they cause two common bugs: stale values (a callback reads a variable from an…
Part 3 · 3 concepts
Functions and this
- 09
Function forms and arrow functions
Functions are values you can store, pass and return; arrow functions are a shorter form that has no own this, arguments, super or prototype and cannot be called with new.
- 10
How this is decided
For normal functions this is decided at call time by four rules in order — new, explicit call/apply/bind, a method call obj.fn(), then the default (undefined in strict…
- 11
call, apply and bind
call and apply invoke a function immediately with a chosen this (arguments listed one by one vs as an array), while bind returns a new function with this and any…
Part 4 · 5 concepts
Objects, prototypes and classes
- 12
Objects, property access and key order
Objects are collections of string- or symbol-keyed properties; knowing how to create them, read them safely (?. and ??), check ownership (Object.hasOwn vs in) and copy…
- 13
Property descriptors, getters, setters, freeze and seal
Every property has a descriptor — either a data descriptor (value, writable) or an accessor descriptor (get, set) — plus enumerable and configurable flags, and freeze…
- 14
The prototype chain
Every object has a hidden link, [[Prototype]], to another object; when a property is not found on the object, the engine follows this chain until it finds it or reaches…
- 15
What new does, and constructor functions
new F(args) creates a fresh object whose [[Prototype]] is F.prototype, runs F with this set to that object, and returns it — unless F returns its own object, which then…
- 16
Classes: fields, #private, static and super
A class is a special constructor with a strict-mode body, methods on the prototype, per-instance fields, real privacy with #names, static members on the class itself…
Part 5 · 4 concepts
Arrays, collections and copying
- 17
Array methods: mutating vs copying
Know which array methods change the array in place (push, pop, shift, unshift, splice, sort, reverse, fill, copyWithin) and which return a new array (map, filter…
- 18
Map, Set, WeakMap and WeakSet
Use Map for key-value data with any key type, frequent adds and deletes, and guaranteed insertion order; Set for unique values; and WeakMap or WeakSet when the key is…
- 19
Shallow copy, deep copy and structuredClone
Spread and Object.assign copy only the top level; structuredClone makes a real deep copy of plain data (including Map, Set, Date and cycles) but throws on functions and…
- 20
JSON.stringify and JSON.parse in depth
JSON.stringify converts values by fixed rules — it calls toJSON, drops undefined, functions and symbols in objects (but writes null in arrays), turns NaN and Infinity…
Part 6 · 3 concepts
Symbols, iterators, generators and Proxy
- 21
Symbols and the iteration protocol
A Symbol is a unique primitive used as a collision-free property key and as a hook into language behaviour (Symbol.iterator, Symbol.toPrimitive, Symbol.asyncIterator)…
- 22
Generators
A generator function (function*) returns an iterator that runs its body only on demand and pauses at each yield; next(value) resumes it and sends a value in, which…
- 23
Proxy and Reflect
A Proxy wraps an object and lets you intercept basic operations (get, set, has, deleteProperty, apply, construct and more) with trap functions, and Reflect provides the…
Part 7 · 3 concepts
Modules, errors and memory
- 24
ES modules vs CommonJS
ES modules use static import and export that are linked before code runs (enabling tree shaking, live bindings and top-level await), while CommonJS require runs…
- 25
Errors: types, try/catch/finally and cause
JavaScript errors are objects (TypeError, ReferenceError, RangeError, SyntaxError and others) thrown with throw and caught by the nearest try/catch on the current call…
- 26
Garbage collection, WeakMap and WeakRef
JavaScript frees memory automatically: the garbage collector keeps everything reachable from roots (globals, the current call stack, closures still in use) and reclaims…
Part 8 · 5 concepts
The event loop
- 27
One thread, run-to-completion and callbacks
JavaScript runs your code on one thread and finishes each piece of work completely before starting the next (run-to-completion); slow work like network requests and…
- 28
The event loop, step by step
The event loop repeats one cycle: take the oldest task from a task queue and run it to completion, then run every microtask until the microtask queue is empty, then let…
- 29
Microtasks vs macrotasks in practice
A macrotask (task) is one unit of work such as a timer callback or a click handler, and one runs per loop turn; microtasks (promise reactions, await continuations…
- 30
Splitting heavy work: setTimeout, scheduler.yield and Web Workers
Any task over 50 ms is a long task that blocks clicks and paints, so heavy JavaScript must be split into chunks that yield back to the event loop (setTimeout…
- 31
The Node.js event loop: nextTick, setImmediate and timers
Node's event loop (libuv) runs in phases — timers, pending callbacks, poll (I/O), check (setImmediate), close — and between callbacks it first drains the…
Part 9 · 4 concepts
Promises in depth
- 32
Promises: states, the executor and settling once
A promise is an object for a future result that starts pending and settles exactly once, to fulfilled with a value or rejected with a reason; the executor passed to new…
- 33
Chaining, error propagation, catch and finally
Every .then, .catch and .finally returns a new promise: returning a value fulfills it, throwing rejects it, returning a promise makes it follow that promise, and a…
- 34
How promises resolve inside: jobs and extra ticks
Settling a promise queues one microtask (a reaction job) per attached handler, but resolving a promise with another promise or thenable costs extra microtask hops (one…
- 35
Promise.all, allSettled, race and any
Promise.all fulfills with all values in input order or rejects on the first rejection, allSettled waits for everything and never rejects, race settles with the first…
Part 10 · 4 concepts
async/await exactly
- 36
What async and await do, exactly
An async function always returns a promise and runs synchronously until its first await; await x turns x into a promise, pauses only this function (not the thread)…
- 37
Error handling with async/await (return vs return await)
Inside an async function, try/catch catches a rejection only if you await it inside the try block — return promise without await hands the promise out before the try…
- 38
Sequential vs parallel async work
Awaiting inside a loop runs tasks one after another (total time = the sum), while starting them all and awaiting Promise.all runs them concurrently (total time ≈ the…
- 39
Async iterators, async generators and for await
An async iterator's next() returns a promise of { value, done }, async function* produces one, and for await...of consumes it one item at a time — the natural tool for…
Part 11 · 2 concepts
Output prediction drills
- 40
Predicting async output: a method
To predict any event-loop puzzle, label every line as sync, microtask or task; run all sync code first; then drain microtasks in the order they were queued (a chained…
- 41
Predicting sync output: hoisting, this, coercion and references
Most non-async output questions test five rules you already know — hoisting and the TDZ, how this is bound at the call site, coercion in + and ==, references vs copies…
Part 12 · 5 concepts
Cancellation and concurrency control
- 42
AbortController, cancellation and race conditions
An AbortController gives you a signal you pass to fetch, event listeners or your own async functions, and calling abort() cancels them; combine it with a…
- 43
Concurrency limit: the promise pool
A promise pool runs many async tasks with at most N in flight: start N workers, and each time a task finishes start the next one, storing each result at its input index…
- 44
Retry with exponential backoff and timeouts
A retry helper re-runs a failing async function a limited number of times, waiting longer each time (base × 2^attempt plus random jitter), retries only errors that can…
- 45
Batching and rate limiting
A batcher collects items and sends them together when the batch is full or a timer expires, whichever comes first, and a rate limiter allows at most N calls per time…
- 46
Async task queues, schedulers and chainable APIs
Many senior JavaScript tasks are the same idea in different clothes: keep a queue of pending work, run it one at a time (or N at a time) with promises, and expose a…
Part 13 · 3 concepts
Functional patterns
- 47
Higher-order functions, compose, pipe and middleware
A higher-order function takes or returns a function; compose(f, g)(x) is f(g(x)) (right to left), pipe runs left to right, and Koa- or Redux-style middleware is…
- 48
Currying, partial application and infinite currying
Currying turns f(a, b, c) into f(a)(b)(c) by returning a closure that collects arguments until it has fn.length of them, while infinite currying like sum(1)(2)(3)()…
- 49
memoize, once and caching functions
Memoization wraps a pure function with a cache keyed by its arguments so repeated calls return the stored result; the senior details are the key strategy (JSON vs…
Part 14 · 7 concepts
Polyfills interviewers ask
- 50
Polyfill ground rules (and why not to extend built-ins)
A polyfill adds a missing standard API with exactly the spec's behaviour, only when it is missing, as a non-enumerable property — and you should never add your own…
- 51
bind, call and apply polyfills
myCall temporarily attaches the function to the context object under a unique Symbol key and calls it as a method, and myBind returns a normal function that calls the…
- 52
Array polyfills: map, filter, reduce and flat
Array method polyfills loop over indexes and use i in this to skip holes, call the callback with (element, index, array) and the optional thisArg, and reduce must start…
- 53
Promise.all, allSettled, race and any polyfills
All four promise combinators share one skeleton — return a new Promise, turn the iterable into an array, wrap each item with Promise.resolve, store results by index…
- 54
Build a Promise from scratch
A minimal Promise is a state machine (pending -> fulfilled or rejected, once) with a list of handlers; then returns a new promise that resolves with the handler's…
- 55
Debounce (with leading, trailing, cancel and flush)
Debounce delays calling a function until it has not been called for wait ms — every call clears the previous timer and starts a new one — with options for a leading…
- 56
Throttle (and why the flag version loses the last call)
Throttle lets a function run at most once per wait ms: the first call can run immediately (leading) and, if more calls arrive during the wait, one trailing call runs at…
Part 15 · 6 concepts
Utility functions
- 57
Deep clone and deep equal
A hand-written deep clone recursively copies arrays and plain objects (plus Date, Map, Set and RegExp when asked) and uses a WeakMap of already-copied objects to handle…
- 58
Flatten arrays and objects (and unflatten)
Flattening an array removes nesting up to a depth (with recursion or an explicit stack), and flattening an object turns nested keys into dot paths like { 'a.b': 1 } —…
- 59
EventEmitter, pub/sub and a mini Redux store
An EventEmitter keeps a Map from event name to a list of listeners, with on (returning an unsubscribe function), once, off and emit; the same subscribe-and-notify core…
- 60
LRU cache
An LRU cache keeps at most capacity entries and evicts the least recently used one; in JavaScript a Map does this in O(1) because it remembers insertion order — on get…
- 61
get/set by path, classnames and key casing
Many utility questions are small recursive walks over objects: read or write a value by a path like 'a[0].b', build a class string from mixed arguments (classnames)…
- 62
Flat list to tree (and back)
Turning a flat list of { id, parentId } rows into a nested tree takes O(n) with one pass that builds an id -> node map and another that attaches each node to its…
Part 16 · 2 concepts
Modern JavaScript
- 63
Modern JavaScript you will actually use (ES2022–ES2025)
The recent features worth using and naming in interviews are copy-returning array methods (ES2023), Object.groupBy and Promise.withResolvers (ES2024), and iterator…
- 64
ES2026 and what comes next (Temporal, using)
ES2026 adds RegExp.escape, Error.isError, Math.sumPrecise, Array.fromAsync, Uint8Array base64/hex, Iterator.concat, Map/WeakMap getOrInsert and JSON.parse source text…
Your first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.