Explain clearTimeout() function in Node.js
In node.js, there exists a timer module that is used to schedule timers and execute some kind of functionality in some future time period.
Example: The setTimeout inside the script tag is registering a function to be executed after 3000 milliseconds and inside the function, there is only an alert.
Hi, 3 Second completed!
Example: Here we have stored the timer id returned by setTimeout, and later we are passing it to the clearTimeout method which immediately aborts the timer.
Output: Here we will not be able to see that alert registered to be executed after 3000 milliseconds because clearTimeout canceled that timer object before execution.
Timer has been Canceled
Please Login to comment...