An Introduction to Promises and Async Programming

By Codehouse
20 Nov 2020

At some point in development you may find yourself using a callback. There’s nothing wrong with that, but then you realise you need another callback to fire after the first callback, and so on. This is referred to as ‘Callback Hell!’

Callbacks are a convention of JavaScript and are the same as any other function. The difference is not what’s inside them, but when they’re used.

Callbacks are typically used after a task that takes time to complete. JavaScript is generally synchronous. It will complete one task before moving onto the next, but developers aren’t keen on waiting for tasks with unknown completion times.

What happens if the task doesn’t even finish and throws an error half way through the process? This is where the use of Promises and Asynchronous programming come in.

DevelopmentTech

Latest news