Last active
July 3, 2020 03:44
-
-
Save marta-krzyk-dev/70a2d1c4f7e43662d132d95d42595aa1 to your computer and use it in GitHub Desktop.
Simplest Promise in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Based on: https://www.youtube.com/watch?v=s6SH72uAn3Q | |
let promiseToCleanRoom = new Promise(function(resolve, reject) { | |
//cleaning the room | |
let isClean = false; | |
if (isClean) | |
resolve('Clean'); | |
else | |
reject('Dirty'); | |
}); | |
promiseToCleanRoom.then(function(fromResolve){ | |
console.log('the room is ' + fromResolve); | |
}).catch(function(fromReject){ | |
console.log('the room is ' + fromReject); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment