See the problem here? We are basically having our computer/browser busy by running a "nonsense" loop and comparing dates just for the fact of getting our delay. while loop that will only exit if more than 1000 milliseconds have passed since we started the loop. ![]() We basically check the current time with the Date function and we create a do. log ( "Executed now" ) wait ( 1000 ) console. log ( "Executed now" ) // 1 second delay setTimeout ( function ( ) console. One of the easiest way to achieve a 1 second delay is by using the setTimeout function that lives on the window global object. Some are better than others and some should only be used in specific circumstances. There are quite a few ways to tell JavaScript to wait for 1 second. To force a 1 second pause or delay in JavaScript we can use the setTimeout function, but if we want a better solution we should use the Promise function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |