There are two very import built-in functions in JavaScript. This registered in window object.
setTimeout: This function accepts two arguments.
Example:
setTimeout(function(){console.log("Here I am");},2000);
setInterval: Another important function is the setInterval function which can be used to call periodically a function.
We can use setInterval in combination with setTimeout to create really interesting stuffs. Below is one example.
var interval = setInterval(function(){console.log("Inside setInterval");},200);
setTimeout(function(){clearInterval(interval);},1000)
Refer:
https://alligator.io/js/settimeout-setinterval/
Practice at:
http://jsbin.com
- setTimeout
- setInterval
setTimeout: This function accepts two arguments.
- Function , named or closures (anonymous functions)
- Time period in milliseconds, this setTimeout must wait before executing the function.
Example:
setTimeout(function(){console.log("Here I am");},2000);
setInterval: Another important function is the setInterval function which can be used to call periodically a function.
We can use setInterval in combination with setTimeout to create really interesting stuffs. Below is one example.
var interval = setInterval(function(){console.log("Inside setInterval");},200);
setTimeout(function(){clearInterval(interval);},1000)
Refer:
https://alligator.io/js/settimeout-setinterval/
Practice at:
http://jsbin.com
No comments:
Post a Comment