Question #93

Author: admin
tags: JavaScript  
Code in a JavaScript module (top level await is allowed):
async function* gen() {
  let i = 0;
  while(true) {
    yield await new Promise((resolve) => {
      setTimeout(() => {
        i++;
        resolve(i);
      }, 1000);
    });
  }
}

const counter = gen();

for await (const value of counter) {
  console.log(value);
}

console.log('end');
What messages will be output to the console?
Every second a new number will be shown, increased by 1, the word "end" will not be shown
Every second a new number will be shown, increased by 1, until the counter reaches 1000, then the word "end" will appear
Only the word "end" will appear
None, because the browser will freeze due to an infinite loop
None, because there is a syntax error in the code
Rate the difficulty of the question:
easyhard