(function () { let counter = 0; const countdown = () => { let inner_timeout = setTimeout(countdown, 1000); if (counter === 5) { clearTimeout(inner_timeout); } console.log(counter === 5 ? console.log("поехали!") : 5 - counter); counter++ } setTimeout(countdown, 1000); })(); // или for (let i = 0; i <= 5; ++i) { setTimeout(() => { i === 5 ? console.log("поехали!") : console.log(5 - i); }, 1000 * i); }