Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardJavaScriptclosures and memory retentionSingle-choice MCQ

In the loop below, what is the under-the-hood reason each closure captures a distinct value of i, and what does that imply about heap allocation?

const fns = []; for (let i = 0; i < 3; i++) { fns.push(() => i); }