Skip to solution
mediumFrontend

What is memoization?

1.1k views
01

Understand the problem

Question presented to candidate: "What is memoization, when does it actually help, and can you show it genuinely speeding up a repeated call?"

What a strong answer should cover:

  • Memoization caches a function's return value, keyed by its input arguments, so a repeated call with the SAME arguments returns instantly instead of recomputing.
  • It only produces correct results for pure functions — ones whose output depends only on their arguments, with no reliance on external mutable state and no side effects to skip.
  • It is a classic time-for-memory tradeoff: faster repeated calls, at the cost of holding cached results in memory for as long as the cache lives.
  • The cache key for multi-argument functions typically needs a resolver (e.g. JSON.stringify-ing the argument list, or a custom key function) — a plain single argument can often be used as the key directly.
  • Real verification: proving with a real timing measurement that a cached call is genuinely faster, not just assuming a Map lookup is fast.

Clarifying questions expected:

  • "Should the cache ever be cleared or bounded in size, or is an unbounded cache acceptable for this exercise?" (a strong candidate flags unbounded-cache memory growth as a real production concern)

Code / implementation expected: Yes — a short, genuinely runnable memoize implementation with a real, measured before/after timing comparison.

memoization
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals / performance interview questions. Difficulty: Easy-Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every result below was actually run on Node.js v24.19.0 — the

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSMemoize wrapper with a real measured speedup (run directly)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 51 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track