Javascript Flashcards

1
Q

What does function* keyword does?

A

It declares a generator function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does a generator function return?

A

A generator function returns a Generator object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe how does a generator function work when it is called.

A

Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator’s next() method is called, the generator function’s body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function. The next() method returns an object with a value property containing the yielded value and a done property which indicates whether the generator has yielded its last value as a boolean.

A return statement in a generator, when executed, will make the generator done. If a value is returned, it will be passed back as the value. A generator which has returned will not yield any more values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you call next(arg) with an argument in a Generator object?

A

Calling the next() method with an argument will resume the generator function execution, replacing the yield expression where execution was paused with the argument from next().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly