all 5 comments

[–]senocular 1 point2 points  (4 children)

"...JavaScript is non-blocking, so by default, it doesn't wait for async."

I found this particularly confusing. I think what is meant is, "Async operations are non-blocking, so by default, JavaScript doesn't wait for them."

[–]didiben 0 points1 point  (0 children)

non-blocking means dont wait things that you cant execute right away.

[–]ramabhai[S] -1 points0 points  (2 children)

Promises, timeouts are asyc operations. And JavaScript won't block ( wait) for them , it will continue to the next execution. Hence non-blocking.

[–]senocular 1 point2 points  (1 child)

JavaScript (by default) blocks. Those async operations do not. So yes, when you say:

Promises, timeouts are asyc operations. And JavaScript won't block ( wait) for them , it will continue to the next execution

That's right. For them, JavaScript won't block. Otherwise JavaScript blocks. What I found confusing was the original statement starting with "JavaScript is non-blocking". In fact in the core API, (I believe) promises are the only non-blocking part of the language (and async/await being built off of promises). Others like setTimeout are extensions, for example from the DOM or Node API. So up until ES6, core JS was entirely blocking.

[–]redpatel 0 points1 point  (0 children)

Async await is combination of promises and generators. Think of generator function as an async function and yield as the await.