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

  1. 3.1 Types, values and coercion
  2. 3.2 Equality, operators and numbers
  3. 3.3 Scope, hoisting and declarations
  4. 3.4 Closures and higher-order functions
  5. 3.5 this, call, apply and bind
  6. 3.6 Prototypes and classes
  7. 3.7 Objects, arrays and destructuring
  8. 3.8 Modules, strict mode and modern syntax
  9. 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

  1. What does this log? ```js console.log(typeof null); ```

    1. `"null"`
    2. `"undefined"`
    3. `"object"`
    4. It throws a TypeError

    Answer: C. `"object"` A long-standing quirk from the first JavaScript engine; check for null with `x === null`.

  2. What is the result of `0.1 + 0.2 === 0.3`?

    1. A RangeError, because the precision limit is exceeded
    2. `true`, because JavaScript rounds sums to 15 digits
    3. `false`, because doubles can't store 0.1 and 0.2 exactly
    4. `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.

  3. What does this log? ```js console.log(a); var a = 5; ```

    1. `null`
    2. `undefined`
    3. `5`
    4. A ReferenceError

    Answer: B. `undefined` `var` declarations are hoisted and initialized to undefined; the assignment stays where it is.

  4. What does an IIFE such as `(function () { /* ... */ })();` give you?

    1. A generator function that can be paused
    2. Code that runs at once with its own private scope
    3. A global function that's available everywhere
    4. 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.

  5. What does this log? ```js const user = { name: "Ada", greet() { return this.name; }, }; const greet = user.greet; console.log(greet()); ```

    1. `"greet"`, the name of the function that was called
    2. `"Ada"`, because the method remembers the object it came from
    3. `null`, because detached methods always return null
    4. 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)`.

  6. What does `new Person("Ada")` do, in order?

    1. Creates an instance only if Person was declared with `class`
    2. Copies all of Person's methods onto a brand-new plain object
    3. Creates an object linked to `Person.prototype`, runs `Person` on it, returns it
    4. 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.

  7. What is the difference between `const` and `Object.freeze` for an object?

    1. `const` makes the object deeply immutable, `freeze` doesn't
    2. `freeze` blocks reassignment; `const` blocks property changes
    3. `const` blocks reassignment; `freeze` blocks property changes
    4. 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.

  8. In non-strict code, what happens when you assign to an undeclared variable, `total = 10`?

    1. It creates a global property; strict mode throws instead
    2. It always throws a SyntaxError, in any mode
    3. The assignment is silently ignored and nothing changes
    4. 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.

  9. How can closures cause a memory leak in a long-lived page?

    1. A forgotten listener's closure keeps large objects reachable
    2. Each closure copies every variable in the whole program
    3. Each closure allocates its own thread and stack
    4. 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.

  10. What does this log? ```js console.log([1, 2, 3] + ""); ```

    1. `"[1,2,3]"`
    2. `"1,2,3"`
    3. `"123"`
    4. `"6"`

    Answer: B. `"1,2,3"` Arrays convert to strings with `join(",")` when used with the `+` operator and a string.

Practice all 2,635 questions

More Front End