Skip to content

Instantly share code, notes, and snippets.

@perbu
Created July 18, 2019 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perbu/5a218c25dafdf7c456ae131d88ac5994 to your computer and use it in GitHub Desktop.
Save perbu/5a218c25dafdf7c456ae131d88ac5994 to your computer and use it in GitHub Desktop.
/*
This prints out A,B,C,D and E.
What is the order and what is printed after E:
*/
myAdd = (a, b) => {
return new Promise((resolve, reject) => {
resolve(a + b);
});
};
let numbers = [];
console.log("A");
for (let i = 0; i < 1; i++) {
console.log("B");
myAdd(i, i * 2)
.then((res) => {
console.log("C");
numbers[i] = res;
})
.catch((err) => console.log("Err:", err));
}
console.log("D");
console.log("E:", numbers);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment