A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java-script-settimeout-setinterval-method/ below:

JavaScript setTimeout() & setInterval() Method

JavaScript setTimeout() & setInterval() Method

Last Updated : 11 Jul, 2025

JavaScript SetTimeout and SetInterval are the only native function in JavaScript that is used to run code asynchronously, it means allowing the function to be executed immediately, there is no need to wait for the current execution completion, it will be for further execution.

JavaScript
setTimeout(gfg1, 2000);
function gfg1() {
    console.log("gfg1");
}
function gfg() {
    console.log("gfg");
}
setInterval(gfg, 1000);

Output:

gfg
gfg1
gfg
......
Key points: JavaScript setTimeout() Method

The setTimeout() Method executes a function, after waiting a specified number of milliseconds. 

JavaScript
setTimeout(gfg1, 2000);
function gfg1() {
    console.log("gfg1");
}

Output:

gfg1
JavaScript setInterval() Method

The setInterval() method repeats a given function at every given time interval. 

JavaScript
function gfg() {
    console.log("gfg");
}
setInterval(gfg, 1000);

Output: After every second a new "gfg" message will be displayed.

Interesting Facts

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


SetTimeout,SetInterval and clearInterval clearTimeout

Visit Course

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4