Reputation: 2188
I'm studing async JS now and trying this:
function printOne() {
console.log(1);
}
function printTwo() {
console.log(2);
}
setTimeout(printOne, 1000);
setTimeout(printTwo, 0);
In return I got something like this:
<99350
2
1
The question is: what's 99350 mean? I understand that it's something about time, but why does console return it to me?
Upvotes: 2
Views: 130
Reputation: 386620
It is just the timeoutID
, the return value from setTimeout
The returned
timeoutID
is a numeric, non-zero value which identifies the timer created by the call tosetTimeout()
; this value can be passed toWindowOrWorkerGlobalScope.clearTimeout()
to cancel the timeout.It may be helpful to be aware that
setTimeout()
andsetInterval()
share the same pool of IDs, and thatclearTimeout()
andclearInterval()
can technically be used interchangeably. For clarity, however, you should try to always match them to avoid confusion when maintaining your code.
function printOne() {
console.log('printOne', 1);
}
function printTwo() {
console.log('printTwo', 2);
}
console.log('timeoutID', setTimeout(printOne, 1000));
console.log('timeoutID', setTimeout(printTwo, 0));
Upvotes: 3