I am hearing that setTimeout()
, the Web API is not included in JavaScript quite often. So, if it is only Web API it is natural to think as it won't work anywhere except in the browser. So, why setTimeout
is working in my terminal when I just run a plain old JS file with the node ${filename}
command?
Asked
Active
Viewed 416 times
3

Ahmad Shahbalayev
- 66
- 1
- 8
-
1Check https://nodejs.org/en/docs/guides/timers-in-node/#when-i-say-so-execution-settimeout – Tanay Apr 17 '22 at 05:08
-
Thanks you! So it is Node related feature and JS have nothing to do with that yes? Is the statement JS do not have `setTimeout` right? – Ahmad Shahbalayev Apr 17 '22 at 09:09
1 Answers
4
The browser and node.js both have a global setTimeout
function, but the return types are different between the two.
- node.js setTimeout returns a Timeout object: https://nodejs.org/api/timers.html#settimeoutcallback-delay-args
- Browser setTimeout returns an integer timer id: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

dlannoye
- 1,746
- 19
- 19
-
So is this means that Node JS has own Callback Queue and some API to count? Cool did not know! Thanks for info! – Ahmad Shahbalayev Apr 17 '22 at 09:07