Apr 6, 2022
setTimeout() | A Crazy Method
Be with me and get to know everything.
- A web API, which we get from the browser.
- A Global method that sets a timer and executes a function or a specific piece of code once the timer expires.
- Syntax < setTimeout(function[,delay]) >
function: can be any function that will be executed after the timer expires.
delay: time in milliseconds that the timer should wait before the specific function or code is executed. - Let's check with an example
In the above pic, we can see that their line-9 is getting consoled first then the line-6.
4. Now to have more clarity we will try to print 1to 10 in a sequence with the difference in timing
Click on the link and see the magic by yourself https://replit.com/@mdasifr28/setimeout#index.js