Hello Everyone!
It’s time for fun Puzzle!
Here I have attached some fun Puzzles related to CallStack | Promises:
Please execute and reply your answer!
1)What will be the output of the following code?
function foo() {
console.log("Hello");
}
function bar() {
foo();
console.log("World");
}
bar();
2)What will be the output of the following code?
console.log("Start");
new Promise((resolve, reject) => {
console.log("Promise executor");
resolve("Promise resolved");
}).then((result) => {
console.log(result);
});
console.log("End");
3)What will be the output of the following code?
console.log("Start");
Promise.resolve("Promise resolved").then((result) => {
console.log(result);
});
console.log("End");
4) What will be the output of the following code?
var x = 10;
function foo() {
console.log(x);
var x = 20;
}
foo();
5)What will be the output of the following code?
function foo(callback) {
setTimeout(() => {
console.log("Hello");
callback();
}, 0);
}
function bar() {
console.log("World");
}
foo(bar);
Have a Happy Learning
Thanks & Regards
Teaching Assistant,
Dharshini M.