Question: In JavaScript, what is the easiest alternative to set Timeout(fn, 0)? For example, consider the behavior of (function() { console.log('this is the start'); setTimeout(function cb()
In JavaScript, what is the easiest alternative to set Timeout(fn, 0)?
For example, consider the behavior of
(function() {
console.log('this is the start');
setTimeout(function cb() {
console.log('Callback 1: this is a msg from call back');
}); // has a default time value of 0
console.log('this is just a message');
setTimeout(function cb1() {
console.log('Callback 2: this is a msg from call back');
}, 0);
console.log('this is the end');
})();
// "this is the start"
// "this is just a message"
// "this is the end"
// "Callback 1: this is a msg from call back"
// "Callback 2: this is a msg from call back"
What are some alternatives which would still allow everything in the queue to finish before fn?
Step by Step Solution
3.41 Rating (157 Votes )
There are 3 Steps involved in it
The best alternative will be setImmediate if youre u... View full answer
Get step-by-step solutions from verified subject matter experts
