简体   繁体   中英

Javascript setTimeout sequence

Say I have this line of javascript-

setTimeout(function() { console.log("okay"); }, 5000);
/* Blah blah- more code */

Is that going to wait 5 seconds, run the console.log() , then continue on the the rest of the script?

OR

Is it going to set the console.log() to be ran in 5 seconds while its already went ahead and is running the rest of the code?

setTimeout() will set the console.log() to be run in 5 seconds and continue running the remaining code immediately.

In other words, setTimeout() calls it's target code asynchronously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM