September 2018
Intermediate to advanced
302 pages
7h 17m
English
As a quick recap on symbols in JavaScript: CallingSymbol() returns a unique symbol value. A symbol value should be treated as an ID, for instance, as an ID to be used as a key in an object.
To define an iterator for a collection, you need to specify the special key, Symbol.iterator. If such a symbol is defined, we say that the collection is iterable. See the following:
// Array is iterable by default,// we don't need to create a custom iterator,// just use the one that is present.const alpha = ['a','b','c'];const it = alpha[Symbol.iterator]();it.next(); //{ value: 'a', done: false }it.next(); //{ value: 'b', done: false }it.next(); //{ value: 'c', done: false }it.next(); //{ value: undefined, done: true }
Let's ...
Read now
Unlock full access