Day 54: Callbacks and Promises

Dan Esmail - 2/23/2023

Intro

With me not really knowing that much about promises I felt the need to do a little studying on the topic. I spent some time looking at blog posts about promises and callbacks from Freecodecamp.com they were helpful in understanding the topics. The promise post also brought up the topic of callbacks. I can't say that I knew a bunch about callbacks. This article helped me understand the topic a little bit more.

Callbacks

After reading the article on callbacks I found out that it's all about calling a function within a function as an argument. The main point is that you can use a function as an argument and call it within the function. Why is this helpful? Well sometime you want functions to fire off in a chain instead of syconously. Like function 1 run and once it's finish run function 2. That's ayscrannous coding and exactly what callbacks are for.

Promises

Now promises are the ultimate form of callbacks in my opinion. Now when you want to run a callback but you have to wait for data and you don't want to stop your entire program well waiting for that data. Well you have the beautiful thing called promises. A promise goes hey I'll run this in the background while you do everything else and I'll come back with the anwser that your looking for. Now you also have a resolve and a reject for arguments. These will be your first two arguments for the promises and will handle the function if it works or if it fails. Once you have it sorted out if it fails or passes what do you use? That's where the then() method comes in. This is a method that chains to the resolve or reject and tells the program what to do next.



Day 1

Day 1