I'm trying to verify the order in which the following code happens.
function square(n) {
return n * n;
}
setTimeout(function(){
console.log("Hello");
}, 0);
console.log(square(2));
setTimeout() is popped off the stack, and then anonymous() goes to the queue.
While setTimeout() is on the stack, anonymous() goes to the queue, and then setTimeout() is popped off the stack.
Which of the above is the correct order? I tried it on this link and what I've noticed is that setTimeout() is popped of first and then anonymous() goes to the queue but I just need to verify this.