Foreword: want to write semicolon to the front end after all, each have each view, I have no this habit anyway. And then, when I’m screwed, I have something to say.

What happened was that someone in the group posted a code:

function * fibs(){
    let a = 0;
    let b = 1;
    while(true) {yield a;
        [a, b] = [b, a + b];
    }
}
[first, second, third, fourth, fifth, sixth] = fibs()
sixth / / 5
Copy the code

The question is how does this code read, does it not die? Of course, I see that this code is the result of Curious’s final array deconstruction assignment. If this code works, it confirms my guess. Try to move the hands of the state of mind to try:

function * fibs(){
    let a = 0, b = 1;
    while(true) {yield a;
        [a, b] = [b, a + b]
    }
}
[first, second, third, fourth, fifth, sixth] = fibs()
sixth/ / [1, 1)
Copy the code

Oh, what the hell? Why is it different?

Then, searching, trying more and more more collapse, no, I have to write the original picture:

function * fibs(){
    let a = 0;
    let b = 1;
    while(true) {yield a;
        [a, b] = [b, a + b];
    }
}
[first, second, third, fourth, fifth, sixth] = fibs()
sixth / / 5
Copy the code

I think you know, it’s the semicolon that makes the difference.

Once this problem is solved, I will consider the previous question. Does es6’s array deconstruction assignment call next directly? Look up the exporting ES6 — Destructuring, first line.

Well, this is a little bit tricky, and I’m not sure if it’s just yield, if you don’t add semicolons, he thinks you’re not done with the expression, but it’s kind of tricky, and hopefully you’ll make it a habit to add semicolons.

First time post, everybody big guy light spray ha.