Skip to content

Instantly share code, notes, and snippets.

@darrentorpey
Created July 28, 2021 19:08
Show Gist options
  • Save darrentorpey/18a43eef21ed89800138027505b4add1 to your computer and use it in GitHub Desktop.
Save darrentorpey/18a43eef21ed89800138027505b4add1 to your computer and use it in GitHub Desktop.
Demonstrating JS closures and promises
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