JavaScript fundamentals: types, coercion, equality, operators, numbers, scope, hoisting, declarations, closures, higher-order functions, this, call, apply, bind, prototypes and classes, objects, arrays and destructuring, modules, strict mode and modern syntax, errors, memory and tricky output – Front End interview prep
2,635 interview-style multiple-choice questions on JavaScript fundamentals: closures, scope, this and prototypes, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 101 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 3.1 Types, values and coercion
- 3.2 Equality, operators and numbers
- 3.3 Scope, hoisting and declarations
- 3.4 Closures and higher-order functions
- 3.5 this, call, apply and bind
- 3.6 Prototypes and classes
- 3.7 Objects, arrays and destructuring
- 3.8 Modules, strict mode and modern syntax
- 3.9 Errors, memory and tricky output
Key terms
3.1 Types, values and coercion
- BigInt
- Arbitrary-precision integer type written with an n suffix
- parseInt
- A function that parses a leading integer prefix of a string in a given radix
- Primitive
- An immutable value that isn't an object: string, number, bigint, boolean, undefined, symbol, null
- Primitive wrapper
- A temporary String, Number, or Boolean object the engine creates so a primitive can receive a property or method lookup
- structuredClone
- Built-in deep copy for structured data, including cycles
- Symbol
- Unique, immutable value used as an object key
- ToNumber
- The abstract operation that converts a value to a Number, used by unary plus and Number()
- ToPrimitive
- The abstract operation that converts an object to a primitive, via Symbol.toPrimitive or valueOf/toString
- Truthy
- A value treated as true in a boolean context; every object is truthy, including [] and {}
- typeof
- An operator that returns a string naming a value's type, such as "number" or "function"
3.2 Equality, operators and numbers
- Falsy
- A value treated as false in a boolean context: false, 0, -0, 0n, "", null, undefined, NaN
- IEEE 754
- The floating-point standard JavaScript Number follows: 64-bit binary, with NaN, infinities, and a signed zero
- Logical assignment
- The operators ||=, &&=, and ??= that assign only when the left side is falsy, truthy, or nullish, and otherwise skip the right-hand side
- Loose equality
- `==`, which converts types before comparing
- Math.trunc
- A function that drops the fractional part of a number, rounding toward zero
- MAX_SAFE_INTEGER
- 2^53 − 1, the largest integer with exact sequential representation
- Nullish coalescing (??)
- Returns the right side only when the left side is null or undefined
- Number.EPSILON
- The difference between 1 and the next representable number greater than 1, equal to 2 ** -52
- Number.isSafeInteger
- A predicate that is true for finite integers from -(2 ** 53 - 1) through 2 ** 53 - 1, the exact consecutive integer range
- Object.is
- A comparison that uses the SameValue algorithm: it treats NaN as equal to NaN and treats -0 as different from 0
- Optional chaining
- `?.` returns undefined instead of throwing on null or undefined
- SameValueZero
- Equality used by includes, Map and Set: NaN equals NaN, -0 equals 0
- Type coercion
- Automatic conversion of a value to another type, as with == and the + operator
3.3 Scope, hoisting and declarations
- Block scope
- Scope created by `{ }` for let, const and class
- Catch binding
- The exception name in a catch clause, scoped only to the catch block
- Default parameter scope
- An intermediate scope for default parameter expressions, between the enclosing scope and the function body
- Function scope
- Scope created by a function; `var` declarations belong to it
- globalThis
- Standard name for the global object in any environment
- Hoisting
- Declarations are processed before code runs; var is initialized to undefined, let/const are not
- IIFE
- A function created and called in one expression, often used to make a private function scope
- Implicit global
- In sloppy mode, an assignment to an undeclared name, which creates a property on the global object
- Lexical scope
- Variable access determined by where code is written
- Named function expression
- A function expression with an inner name that is visible only inside the function, useful for recursion and stack traces
- Per-iteration binding
- A fresh let or const binding created for each loop iteration, so deferred callbacks see that iteration's value
- Shadowing
- An inner declaration hiding an outer one with the same name
- Temporal dead zone
- The time between entering a scope and a let/const declaration, when reading the variable throws
3.4 Closures and higher-order functions
- Closure
- A function plus the variables from the scope where it was created
- Currying
- Turning a multi-argument function into a chain of single-argument calls
- Debounce
- Run a function only after calls have stopped for a set delay
- Function composition
- Chaining functions so each output feeds the next
- Higher-order function
- A function that takes or returns another function
- Lexical environment
- The hidden record of variable bindings a function closes over
- Memoization
- Caching a function's results by its arguments, often with a closure
- Module pattern
- An IIFE or factory that returns privileged functions over private state
- once
- A wrapper that runs a function at most once and reuses the result
- Partial application
- Fixing some arguments to produce a new function
- Pipe
- Left-to-right function composition; pipe(f, g)(x) is g(f(x))
- Predicate
- A function that returns a boolean, often passed to filter, some, every, or find
- Pure function
- Output depends only on input, with no side effects
- Throttle
- Run a function at most once per time interval
3.5 this, call, apply and bind
- apply
- Invokes a function immediately with a chosen this value and an array-like argument list
- Bound function
- The function returned by bind, with this and any pre-filled arguments stored internally
- call
- Invokes a function immediately with a chosen this value and individual arguments
- Default binding
- A bare call fn() uses undefined as this in strict mode, or the global object in sloppy mode
- Explicit binding
- Setting this with call, apply or bind
- Implicit binding
- A method-style call such as obj.fn() uses obj as this
- Lexical this
- Arrow functions take this from the enclosing scope
- Method extraction
- Taking a method off its object, which loses its this
- thisArg
- An explicit this value passed to call, apply, bind, or some array methods
3.6 Prototypes and classes
- bind
- Returns a new function with this (and optionally arguments) fixed
- Class field
- A public or private property installed on each instance (or on the constructor, if static) during class initialization
- instanceof
- Tests whether a constructor's .prototype object sits on a value's prototype chain
- Mixin
- Reusable methods applied to classes to share behavior
- new.target
- The constructor that new or Reflect.construct was originally applied to
- Object.create
- Creates a new object whose prototype is the object you pass, or null
- Private field
- Class member written with # that's inaccessible outside the class
- Prototype chain
- Linked objects JavaScript searches when a property isn't found on the object itself
- Static initialization block
- A static { } block that runs once when the class is defined, with access to private static state
- super
- Keyword for calling parent constructors and methods
- Symbol.species
- A static hook that tells instance methods which constructor to use when they create a new collection
- this
- The object a function is called on; set by the call site, except in arrow functions
3.7 Objects, arrays and destructuring
- Copying array methods
- ES2023 methods such as toSpliced, toSorted, toReversed, and with that return a new array instead of mutating
- Destructuring
- Syntax for unpacking arrays or objects into variables
- Map
- Keyed collection with any key type, insertion order and size
- Object.groupBy
- An ES2024 helper that groups an iterable's items into a null-prototype object keyed by a callback
- Object.hasOwn
- A static that reports whether an object has an own property, even if it has no prototype
- Property descriptor
- An object that describes a property's value or accessor and its writable, enumerable, and configurable flags
- Sparse array
- An array with empty slots, where some indexes below length have no own element
- Spread syntax
- `...` that expands iterables or object properties
- WeakMap
- Map with object keys held weakly, not iterable
- WeakSet
- A collection of objects (and non-registered symbols) held weakly, with add, has, and delete but no size or iteration
3.8 Modules, strict mode and modern syntax
- Directive prologue
- The leading string-literal statements at the start of a script or function body, of which "use strict" is the directive that enables strict mode
- Dynamic import
- The import() function that loads a module at runtime and returns a promise for its namespace object
- ES module
- Standard JavaScript module with static import and export
- Generator
- Function that can pause with yield and resume
- Import attributes
- Host hints on how to load a module, written as with { type: "json" } on a static import or as the second argument to import()
- Iterator helpers
- ES2025 methods such as map, filter, take, and toArray on iterators, which stay lazy until the iterator is consumed
- Live binding
- ESM imports that reflect the exporter's current value
- Numeric separator
- Underscores between digits in a numeric literal, such as 1_000_000, that do not change the value
- Tagged template
- A function call written as tag`...` that receives the cooked string parts (with a .raw property) and the interpolated values
- TC39
- Committee that evolves ECMAScript via staged proposals
3.9 Errors, memory and tricky output
- AggregateError
- An Error subclass that groups several failures in its errors property
- Detached DOM node
- Element removed from the document but still referenced
- Error cause
- `cause` option that chains an underlying error
- FinalizationRegistry
- A registry that can run a callback after a registered object has been garbage-collected
- Garbage collection
- Automatic freeing of memory that's no longer reachable
- Heap snapshot
- DevTools capture of memory objects and their retainers
- Mark-and-sweep
- A garbage-collection algorithm that marks objects reachable from roots, then frees the rest
- reportError
- A browser host function that reports an error as an uncaught exception without throwing in the current stack
- Retainer path
- In a heap snapshot, the chain of references that keeps an object reachable from a GC root
- WeakRef
- A reference that does not keep its target object alive; deref() returns the object or undefined
Sample practice questions
What does this log? ```js console.log(typeof null); ```
- `"null"`
- `"undefined"`
- `"object"`
- It throws a TypeError
Answer: C. `"object"` A long-standing quirk from the first JavaScript engine; check for null with `x === null`.
What is the result of `0.1 + 0.2 === 0.3`?
- A RangeError, because the precision limit is exceeded
- `true`, because JavaScript rounds sums to 15 digits
- `false`, because doubles can't store 0.1 and 0.2 exactly
- `NaN`, because the sum isn't a safe integer
Answer: C. `false`, because doubles can't store 0.1 and 0.2 exactly The sum is 0.30000000000000004. Compare with a tolerance such as `Number.EPSILON`, or work in integers like cents.
What does this log? ```js console.log(a); var a = 5; ```
- `null`
- `undefined`
- `5`
- A ReferenceError
Answer: B. `undefined` `var` declarations are hoisted and initialized to undefined; the assignment stays where it is.
What does an IIFE such as `(function () { /* ... */ })();` give you?
- A generator function that can be paused
- Code that runs at once with its own private scope
- A global function that's available everywhere
- A function that runs on the next event-loop tick
Answer: B. Code that runs at once with its own private scope IIFEs were the standard way to avoid polluting the global scope before modules and block scope.
What does this log? ```js const user = { name: "Ada", greet() { return this.name; }, }; const greet = user.greet; console.log(greet()); ```
- `"greet"`, the name of the function that was called
- `"Ada"`, because the method remembers the object it came from
- `null`, because detached methods always return null
- Not "Ada": `this` is lost, so it's the global `name` or a TypeError
Answer: D. Not "Ada": `this` is lost, so it's the global `name` or a TypeError `this` is set by how a function is called. Calling it plainly loses the object; use `user.greet()` or `user.greet.bind(user)`.
What does `new Person("Ada")` do, in order?
- Creates an instance only if Person was declared with `class`
- Copies all of Person's methods onto a brand-new plain object
- Creates an object linked to `Person.prototype`, runs `Person` on it, returns it
- Calls Person and returns whatever it returns, even a number
Answer: C. Creates an object linked to `Person.prototype`, runs `Person` on it, returns it The prototype link is what lets instances share methods.
What is the difference between `const` and `Object.freeze` for an object?
- `const` makes the object deeply immutable, `freeze` doesn't
- `freeze` blocks reassignment; `const` blocks property changes
- `const` blocks reassignment; `freeze` blocks property changes
- They're identical ways to make an object immutable
Answer: C. `const` blocks reassignment; `freeze` blocks property changes A `const` object can still be mutated; freeze is shallow, so nested objects can still change.
In non-strict code, what happens when you assign to an undeclared variable, `total = 10`?
- It creates a global property; strict mode throws instead
- It always throws a SyntaxError, in any mode
- The assignment is silently ignored and nothing changes
- It creates a block-scoped variable, like `let`
Answer: A. It creates a global property; strict mode throws instead Accidental globals are one reason to use strict mode, which ES modules and classes turn on automatically.
How can closures cause a memory leak in a long-lived page?
- A forgotten listener's closure keeps large objects reachable
- Each closure copies every variable in the whole program
- Each closure allocates its own thread and stack
- Closures stop the call stack from unwinding
Answer: A. A forgotten listener's closure keeps large objects reachable Remove listeners and clear timers so the captured data can be garbage collected.
What does this log? ```js console.log([1, 2, 3] + ""); ```
- `"[1,2,3]"`
- `"1,2,3"`
- `"123"`
- `"6"`
Answer: B. `"1,2,3"` Arrays convert to strings with `join(",")` when used with the `+` operator and a string.
More Front End
- HTML semantics & accessibility
- CSS: box model, Flexbox, Grid
- Async JavaScript & the event loop
- TypeScript
- React: components, hooks & rendering
- State management: Redux, Zustand, context
- Angular and Vue basics
- Browser internals & rendering
- Web performance
- Build tools & bundlers
- Front-end testing
- Front-end security
- Mobile & cross-platform