What is a Promise in Javascript? Let& #39;s explain!
Thread
https://abs.twimg.com/emoji/v2/... draggable="false" alt="đź§µ" title="Thread" aria-label="Emoji: Thread">
https://abs.twimg.com/emoji/v2/... draggable="false" alt="👇" title="Rückhand Zeigefinger nach unten" aria-label="Emoji: Rückhand Zeigefinger nach unten">
#100DaysOfCode #CodeNewbies
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)
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!