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

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 & Max
More from @js_test
  1. Sep 30, 2026❓Что будет на выходе? function trickyArgs(a, b, c) { arguments[0] = 10; arguments[1] = 20;…
  2. Sep 29, 2026❓Что будет на выходе? 'use strict'; function strictModeExample() { undeclaredVariable = 10…
  3. Sep 29, 2026Бесплатный вводный урок английского для взрослых Хотите узнать свой уровень английского и…
  4. Sep 28, 2026❗️Что будет на выходе? const arr = []; arr.length = 3; arr[10] = 7; arr.forEach((el, i) =>…
  5. Sep 28, 2026👩‍💻 Всем программистам посвящается! Вот 14 авторских обучающих IT каналов по самым востр…
  6. Sep 27, 2026❗️Что будет на выходе: function processConfig(config) { const cache = config.cache ?? true…
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 →