Hard
What is the purpose of Symbol.iterator in JavaScript, and how can you use it to make a custom iterable object?
1const range = {2 start: 1,3 end: 5,45 [Symbol.iterator]() {6 let current = this.start;7 const end = this.end;8 return {9 next() {10 if (current <= end) {11 return { value: current++, done: false };12 }13 return { done: true };14 },15 };16 },17};1819for (const num of range) {20 console.log(num);21}