Zest.

JavaScript: setTimeout and setInterval

A short, tested JavaScript example for settimeout and setinterval. Copy it and adjust the names and paths for your project.

JavaScript
const t = setTimeout(() => console.log("later"), 1000);
clearTimeout(t);

const id = setInterval(() => console.log("tick"), 1000);
clearInterval(id);

const sleep = ms => new Promise(r => setTimeout(r, ms));
await sleep(500);

Find it in Zest

Search for “javascript settimeout and setinterval” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More JavaScript examples

All JavaScript examples