What type of function can have it's execution suspended and then resumed at a later point in javascript

Answers 1

Answer:

  • The first step is to define our generator “function”. Note that this is done by adding a “*” to the function keyword. We are then defining a function called Add which takes a parameter of x.
  • The yield keyword is a specific to generators. This makes it a powerful construct for pausing a function in the middle of anything. So here, the function execution will be halted till we invoke the next() function, which will be done in Step4. At this point, the value of x will become 6 and the execution of the function will be stopped.
  • This is where we first call the generator function and send the value of 5 to our Add function. This value will be substituted in the x parameter of our Add function.
  • Once we call the next() function, the Add() function will resume the execution. When the next statement var y= yield(null) will be executed, the Add() function will again stop executing.
  • Now after calling the next() function again, the next statements will run, and the combined value of x=5 and y=6 will be added and returned.

Explanation:

If you know the answer add it here!

Can't find the answer?

Log in with Google

or

Forgot your password?

I don't have an account, and I want to Register

Choose a language and a region
How much to ban the user?
1 hour 1 day 100 years