TGViewer
JavaScript test JavaScript test @js_test · 9.68K subscribers
Post #5007 735
❗️Что будет на выходе?

function* counter() {
let i = 0;
while (true) {
const direction = yield i;
if (direction === 'up') i += 2;
else if (direction === 'down') i -= 1;
else i += 1;
}
}

const count = counter();
console.log(count.next().value);
console.log(count.next('up').value);
console.log(count.next('down').value);
console.log(count.next().value);

Ответ: 0 2 1 2

JavaScript test | #JavaScript
More from @js_test
  1. Oct 14, 2026❗️Что будет на выходе: function processData({ a = 10, b = 20 } = { a: 30 }) { console.log(…
  2. Oct 14, 2026Как платить за границей и за зарубежные сервисы в 2026 году? Можно переплачивать посредник…
  3. Oct 14, 2026❗️Что будет на выходе: const person = { name: 'Alice', greet() { return `Hello, I'm ${this…
  4. Oct 14, 2026❗️Что будет на выходе: const regex = /a/g; const str = 'banana'; console.log(str.match(reg…
  5. Oct 13, 2026❓Что будет на выходе? const sym1 = Symbol('description'); const sym2 = Symbol('description…
  6. Oct 13, 2026❗️Что будет на выходе: function Animal(name) { this.name = name; } Animal.prototype.speak…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →