// Basic usage
setTimeout(() => {
console.log('This message is displayed after 2 seconds');
}, 2000);
// With arguments
setTimeout((name) => {
console.log(`Hello, ${name}!`);
}, 1000, 'World');
// Storing and clearing a timeout
const timeoutId = setTimeout(() => {
console.log('This will never be displayed');
}, 5000);
// Cancel the timeout before it executes
clearTimeout(timeoutId);
console.log('Timeout has been cancelled');
Interval executed 1 times Hello, Node.js! Interval executed 2 times Interval executed 3 times Hello, Node.js! Interval executed 4 times Interval executed 5 times Interval stopped