Skip to main content
JavaScript Interview Questions Predict Output P0 Hard

Array holes, named keys and inherited keys

Predict both lines without treating for…in as an index loop.

Official Reference

Code Snippet

const list = [10, , 30];
list.note = "extra";
const proto = Object.create(Array.prototype);
proto.inherited = "parent";
Object.setPrototypeOf(list, proto);
const keys = [], values = [];
for (const key in list) keys.push(key);
for (const value of list) values.push(String(value));
console.log(keys.join(" "));
console.log(values.join(" "));

Expected Output & Explanation

0 2 note inherited
10 undefined 30

for…in sees enumerable string keys up the prototype chain, but not absent indices or non-enumerable length. The array iterator reads numeric positions from zero through length minus one, yielding undefined for the missing index here.

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.