Comment

Comment by ermir

If you have code like:

let x = 0;

doSomethingAsync(); // does not touch x

console.log(x);

There's no guarantee that x will have the value 0 by the time you get to console.log(x). The value of x might have been changed by an outside function that just happened to run between your statements. In synchronous JS this would never happen as callbacks are scheduled to run only at the end of a function, and if they change x the change will only be applied after x is printed.

The change in behavior will break a lot of existing code, since the synchronous behavior of a function is a core feature and assumption of the language.

parent ermir 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton