Notice how our setTimeout function runs asynchronously and that it won't stop the flow of our program. log ( "Executed before the delay, but after the 1st console.log" ) Now, this looks great and simple! However, here's the trick: console. In this case, we are using 1000ms, which is the equivalent of 1 second. One is the callback function that will get executed after a specific time, and the other is the number of milliseconds we want to delay the execution. The setTimeout function takes two parameters. 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 |