Skip to main content
JavaScript Interview Questions Predict Output P1 Hard

Sparse slots vs explicit undefined

Predict the callback count, the slot test and the comparison after spreading.

Official Reference

Code Snippet

const list = [, undefined, 5];
let calls = 0;
const mapped = list.map(x => { calls++; return x ?? 0; });
console.log(calls, 0 in mapped, 1 in mapped);
const spread = [...list];
console.log(0 in spread, spread[0] === spread[1]);

Expected Output & Explanation

2 false true
true true

map skips the absent slot and preserves the hole. Spreading an array consumes its iterator and writes undefined into the new array at index 0.

Module Context & References

JavaScript · Language output drills Trace closures, receivers, prototypes, coercion and array edge cases
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.