Created
May 14, 2020 04:56
-
-
Save PH4N70M-0P5/5aa3bbc5964333268f2223d0631dfef7 to your computer and use it in GitHub Desktop.
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
//the variable myNewPromise is a function that takes | |
//2 arguments, isResolved and IsNotResolved | |
const myNewPromise = new Promise((isResolved, isNotResolved)=>{ | |
// we create a new variable isThePromiseResolved | |
//set it to true because we want it to be resolved.. right now | |
let isThePromiseResolved = true; | |
//what the if statment is saying is, | |
//if (isThePromiseResolved) is true (which it is) | |
if(isThePromiseResolved){ | |
//then we execute isResolved! | |
//this is because isThePromiseResolved is resolved as true | |
// true === resolved | |
//dont worry about the /n it is just a new line | |
isResolved("\n Promise was resolved! \n This is becasue myNewPromise was set to true") | |
//the else is anything that is NOT true | |
}else{ | |
//If myNewPromise is not true | |
//then it will not resolve, or isNotResolved | |
isNotResolved("Promise was not resolved becasue myNewPromise was not true :( ") | |
} | |
}) | |
//Now that we have created what myNewPromise is | |
//we can make the promise! | |
// is myNewPromise is resolved we run isResolved | |
myNewPromise.then(isResolved => console.log(isResolved)) | |
//NOTICE THE .catch this is the equivelent of "else" of a promise, | |
//we use .catch if there are any errors | |
.catch(isNotResolved=>console.log(isNotResolved)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment