1.

What are the difference between setTimeout() and clearTimeout()?

Answer»

setTimeout() : It can be used to schedule CODE EXECUTION after a designated amount of milliseconds.

function myFunc(arg) {
  console.log(`arg was => ${arg}`);
}
setTimeout(myFunc, 1500, 'funky');

clearTimeout()  :  It can be used to CANCEL timeout which are set by setTimeout().

console.log('before IMMEDIATE');
setImmediate((arg) => {
   console.log(`executing immediate: ${arg}`);
}, 'so immediate');
console.log('after immediate');



Discussion

No Comment Found