Nearby lessons
15 of 22JavaScript: setInterval() Method
๐ What is setInterval()?
The setInterval() method repeatedly calls a function with a fixed time delay between each call, until it is cleared using clearInterval().
1๏ธโฃ Basic Usage of setInterval()
This example shows how to print a message every 2 seconds.
Code Example
PREVIEW READY
2๏ธโฃ Using Named Function with setInterval()
You can also pass a named function instead of an anonymous function.
Code Example
PREVIEW READY
3๏ธโฃ Passing Arguments to the Function
You can pass additional arguments to the function being executed by setInterval().
Code Example
PREVIEW READY
4๏ธโฃ Stopping setInterval() using clearInterval()
You can stop the interval by storing the ID and passing it to clearInterval().
Code Example
PREVIEW READY
๐ง Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!AJS - Callback Functions