function f (i) { console.log(1) if(i > 0) setTimeout(function () {f(i-1)}, 0); else console.log(i) } f(40000)