Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptmemoizationSingle-choice MCQ

A developer memoizes a one-argument function using a Map keyed by the argument. Why does this cache produce a stale-looking result here?

function memoize(fn) { const cache = new Map(); return (arg) => { if (cache.has(arg)) return cache.get(arg); const r = fn(arg); cache.set(arg, r); return r; }; } const load = memoize(o => ({ ...o, t: Date.now() })); load({ id: 1 }); const again = load({ id: 1 });