Evgeny Kuznetsov
Evgeny Kuznetsov

Reputation: 2188

Strange return value from Google Chrome console

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

Answers (1)

Nina Scholz
Nina Scholz

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 to setTimeout(); this value can be passed to WindowOrWorkerGlobalScope.clearTimeout() to cancel the timeout.

It may be helpful to be aware that setTimeout() and setInterval() share the same pool of IDs, and that clearTimeout() and clearInterval() 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

Related Questions