![]() ![]() The sleep() function can be used along with the async/await to get the pause between the execution. The features such as promises and async/await function in JavaScript helped us to use the sleep() function in an easier way.Īwait new Promise(r => setTimeout(r, 2000)) Ĭonst sleep = ms => new Promise(r => setTimeout(r, ms)) You can use some approaches for simulating the sleep() function in JavaScript. before getting cleared by below timeout.Ĭonsole.log("Calling after every 1 second") ĬlearInterval(intervalID) //clear above interval after 5 secondsĬonsole.log('This code to be executed after 5 second.') JavaScript Sleep() function - Sleep()With the help of Sleep() we can make a function to pause execution for a fixed amount of time. called 5 times each time after one second ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |