Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumJavaScriptclosures as a patternSingle-choice MCQ

Two methods are returned from the factory. What does this log, and why?

function makeBag() { let items = []; return { add: (x) => items.push(x), all: () => items.slice(), }; } const bag = makeBag(); bag.add('a'); bag.add('b'); console.log(bag.all().join(','));