computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
639 B
639 B
To run a piece of code after a certain time, you can use setTimeout
function in JavaScript. It accepts a function and a time interval in milliseconds. It returns a unique id which you can use to clear the timeout using clearTimeout
function.
const timeoutId = setTimeout(() => {
console.log('Hello World');
}, 1000);
// Output:
// Hello World
In the above code, the setTimeout
function runs the callback function after 1000 milliseconds (1 second) and prints Hello World
to the console. It returns a unique id which you can use to clear the timeout using clearTimeout
function.
clearTimeout(timeoutId);