on-internet
← Community

JavaScript Synchronous Code

Stack Overflow ·

I am confused by some of the terminology on how JavaScript manages its code. Suppose I have some simple code like this: a = 4; var a; function doit() {} a *= 3; setTimeout(…, 0); a /= 2; Promise.resolve().then(() => { a *= 5; }); a += 6; Obviously, the code doesn’t do anything useful. As far as I understand: Each statement is performed synchronously, in order. The setTimeout and Promise statements are executed synchronously, in that they put something something on the task or microtask queues; the task or microtask are then executed later, asynchronously, in the fullness of time. The var and f

Comments

Sign in or sign up to comment and upvote.

No comments yet.