What is a Promise in Javascript? Let's explain!

Thread 🧵👇

#100DaysOfCode #CodeNewbies
Promises in Javascript are a way of isolating something that will likely take a while to complete. Like getting content from another website, or a file
See this code below:

var hello = "Hello world"
console.log(hello)
var number = 5
var numberSquared = 5 * 5
console.log(numberSquared)
You would expect each line to be executed line by line. First, "Hello world" is stored in the "hello" variable, THEN it gets printed, THEN the number variable gets assigned to number 5, THEN it gets squared and FINALLY, the number 25 gets printed in the console. Makes sense!
What if there's something that takes a bit longer to complete? Like getting data from an API? In languages like Python, you'd expect your program to freeze until it's completed!
You can follow @SavvasStephnds.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: