0

Can anyone explain me: why is this wrong:

if (current <= last) {
    //here!
    return
    {
        done: false,
        value: current++
    };
} else {
    return
    {
        done: true
    };
}

and this is right ?

if (current <= last) {
    //error here
    return {
        done: false,
        value: current++
    };
} else {
    return {
        done: true
    };
}

In both cases code returns object, but when i moving first brace of object to a new line code stop working.

CoderPi
  • 12,985
  • 4
  • 34
  • 62
Vlad Morzhanov
  • 1,260
  • 3
  • 14
  • 29

1 Answers1

2

Because "return" and then new line is a complete statement wich will return nothing, because there is nothing after return, it returns undefined.

It's as if you would write return;

CoderPi
  • 12,985
  • 4
  • 34
  • 62