Run in console next code
setTimeout(function(){
console.log(1);
}, 2);
console.log(2);
setTimeout(function(){
console.log(3);
}, 1);
Why 4 values when has only 3? console
Run in console next code
setTimeout(function(){
console.log(1);
}, 2);
console.log(2);
setTimeout(function(){
console.log(3);
}, 1);
Why 4 values when has only 3? console
You get a return value of setTimeout in the console.
The returned
timeoutIDis a numeric, non-zero value which identifies the timer created by the call tosetTimeout();this value can be passed toclearTimeout()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
console.log(setTimeout(function(){
console.log('#' + 1);
}, 2));
console.log('#' + 2);
console.log(setTimeout(function(){
console.log('#' + 3);
}, 1));
20. For future reference, do not include console output or any other text as images. Copy the text and include it in your question. For one, it makes it more searchable.setTimeoutreference, tryvar t = setTime..then printconsole.log(t). Now, why it shows only the first idk.