ABSTRACT

Callbacks quickly become complicated because of: Nesting: a delayed calculation may need the result of a delayed calculation that needs. Error handling: who notices and takes care of errors? Instead of a tangled nest of callbacks, it’s better to use promises, and then to use async and await to make things even easier. JavaScript offers three mechanisms because its developers have invented better ways to do things as the language has evolved, but the simple high-level ideas often don’t make sense unless one should understand how they work. However, a handful of built-in functions delay execution: instead of running right away, they add a callback to a list that the JavaScript interpreter uses to keep track of things that want to be run. When one task finishes, the interpreter takes the next one from this queue and runs it.