Loading…

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

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');

Note: This is very important node js interview question.

Suggest An Answer

No suggestions avaliable!

Latest post from Node js Interview Questions

Ask Question