Modules&Methods

Code. Dev. Design. Anything and everything with a dash of caffeine.

Member-only story

The Lowdown on Promises

Aphinya Dechalert
Modules&Methods
Published in
4 min readMar 18, 2020

--

Mastering the concept of promises is a cornerstone of efficient JavaScript. It makes the task of dealing with asynchronous requests much easier and reduces the potential complexity of your code.

But what exactly are promises? How, when, and where would you use them? And how does promise chaining work?

Well, you’re in the right place to find out!

What Are JavaScript Promises?

The way JavaScript works is that it executes one thing and moves right onto the next. But sometimes you need the code to wait.

JavaScript’s natural flow doesn’t wait for anything. If the value that’s given isn’t right there when it needs it, it will be evaluated based on its current state and not what it’s supposed to be.

This means a variable could be temporary null or undefined — throwing your entire result out of whack.

JavaScript promises allows you to create code that can run in a separate and independent order than the usual flow of things.

Take a look at this diagram:

--

--

Modules&Methods
Modules&Methods

Published in Modules&Methods

Code. Dev. Design. Anything and everything with a dash of caffeine.

Aphinya Dechalert
Aphinya Dechalert

Written by Aphinya Dechalert

🔥 Agree? Clap it up. 💥 Disagree? Let’s fight in the comments. 👉 dechalert.co