Question Bank
/

JavaScript Class, Generator, and Strict-Mode Traces

JavaScript Class, Generator, and Strict-Mode Traces

Four advanced traces covering generator iterator state, the `_id` private-by-convention pattern, strict mode + `Object.defineProperty` enumerability, and try/catch + `var` scope leaks.

Question Bank
Hard
JavaScript
quiz
generators
classes
js-strict-mode

894 views

9

What does the for ... of loop print, and why are 1 and 2 skipped?

Examples

Example 1:

Input: trace the iterator after two manual next() calls
Output: 3; 4; 5; 6; 7
Explanation: A generator iterator is stateful, so the two manual next() calls consume 1 and 2 and the for...of resumes from where the cursor left off.

3 more questions, with full solutions and explanations, are available for premium members.

Upgrade to Premium