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

1 Expert Approved Answer
Step: 1 Unlock

The best alternative will be setImmediate if youre u... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!