Created
July 28, 2021 19:08
-
-
Save darrentorpey/18a43eef21ed89800138027505b4add1 to your computer and use it in GitHub Desktop.
Demonstrating JS closures and promises
This file contains hidden or 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
const people = { | |
1: 'Darren', | |
2: 'Devin', | |
3: 'Sean', | |
}; | |
function reportOnId(id) { | |
return new Promise((resolve, reject) => { | |
const name = people[id]; | |
if (name) { | |
return resolve(name); | |
} else { | |
return reject('No good'); | |
} | |
}); | |
} | |
reportOnId(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment