Let's say I want to assign the result of an ES6 generator to an array variable.
function* gen() {
for(let i = 0; i < 3; i++) {
yield i;
}
}
let [...b] = gen();
console.log(b); // [0, 1, 2]
Here b will be assigned [0, 1, 2]. Why does this work?