Loading snippets...
Preparing your quiz...
Loading snippets...
Preparing your quiz...
console.log('Start');
const promise = new Promise((resolve, reject) => {
console.log('Promise executor');
resolve('Resolved');
});
promise.then((value) => {
console.log(value);
});
console.log('End');What will be the output?
Promise.resolve(1)
.then((value) => {
console.log(value);
return value + 1;
})
.then((value) => {
console.log(value);
})
.then((value) => {
console.log(value);
return Promise.resolve(3);
})
.then((value) => {
console.log(value);
});What will be the output?
const promise1 = Promise.resolve(Promise.resolve(Promise.resolve(1)));
promise1.then((value) => {
console.log(value);
});What will be the output?
console.log('1');
setTimeout(() => {
console.log('2');
}, 0);
Promise.resolve().then(() => {
console.log('3');
});
console.log('4');What will be the output?
Promise.resolve('Start')
.then((value) => {
console.log(value);
throw new Error('Oops!');
})
.then((value) => {
console.log('Hello');
})
.catch((error) => {
console.log('Caught:', error.message);
return 'Recovered';
})
.then((value) => {
console.log(value);
});What will be the output?
const promise = new Promise((resolve, reject) => {
resolve('First');
resolve('Second');
reject('Third');
});
promise
.then((value) => console.log(value))
.catch((error) => console.log(error));What will be the output?
new Promise((resolve, reject) => {
resolve(1);
})
.then((value) => {
console.log(value);
return 2;
})
.then((value) => {
console.log(value);
// No return statement
})
.then((value) => {
console.log(value);
return Promise.reject('Error');
})
.catch((error) => {
console.log(error);
})
.then(() => {
console.log('Done');
});What will be the output?
async function test() {
console.log('1');
await Promise.resolve();
console.log('2');
}
console.log('3');
test();
console.log('4');What will be the output?
const promise1 = Promise.resolve(1);
const promise2 = Promise.reject('Error');
const promise3 = Promise.resolve(3);
Promise.all([promise1, promise2, promise3])
.then((values) => {
console.log('Success:', values);
})
.catch((error) => {
console.log('Failed:', error);
});What will be the output?
Promise.resolve(1)
.then((value) => {
console.log(value);
Promise.resolve(2)
.then((value) => {
console.log(value);
});
return 3;
})
.then((value) => {
console.log(value);
});What will be the output?
const promise1 = new Promise((resolve) => {
setTimeout(() => resolve('Slow'), 1000);
});
const promise2 = new Promise((resolve) => {
setTimeout(() => resolve('Fast'), 100);
});
const promise3 = new Promise((resolve, reject) => {
setTimeout(() => reject('Error'), 50);
});
Promise.race([promise1, promise2, promise3])
.then((value) => {
console.log('Winner:', value);
})
.catch((error) => {
console.log('Failed:', error);
});What will be the output?
Promise.reject('First error')
.catch((error) => {
console.log('Catch 1:', error);
throw new Error('Second error');
})
.catch((error) => {
console.log('Catch 2:', error.message);
return 'Recovered';
})
.then((value) => {
console.log('Then:', value);
throw new Error('Third error');
})
.catch((error) => {
console.log('Catch 3:', error.message);
});What will be the output?
async function func1() {
return 1;
}
async function func2() {
return Promise.resolve(2);
}
func1().then(console.log);
func2().then(console.log);
console.log(3);What will be the output?
Promise.resolve('Success')
.finally(() => {
console.log('Finally 1');
return 'This will be ignored';
})
.then((value) => {
console.log('Then 1:', value);
})
.finally(() => {
console.log('Finally 2');
throw new Error('Finally error');
})
.then((value) => {
console.log('Then 2:', value);
})
.catch((error) => {
console.log('Catch:', error.message);
});What will be the output?
console.log('Start');
setTimeout(() => {
console.log('Timeout 1');
Promise.resolve().then(() => console.log('Promise in Timeout'));
}, 0);
Promise.resolve()
.then(() => {
console.log('Promise 1');
setTimeout(() => console.log('Timeout in Promise'), 0);
})
.then(() => {
console.log('Promise 2');
});
setTimeout(() => {
console.log('Timeout 2');
}, 0);
console.log('End');What will be the output?
const promise = new Promise((resolve, reject) => {
console.log('Executor start');
setTimeout(() => {
console.log('Timeout in executor');
resolve('Done');
}, 0);
console.log('Executor end');
});
promise.then((value) => {
console.log('Then:', value);
});
console.log('After promise creation');What will be the output?
function outer(x) {
function middle(y) {
function inner(z) {
console.log(x + y + z);
}
let x = 10;
inner(3);
}
middle(2);
}
outer(1);What will be the output?
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
console.log('Hello, I am ' + this.name);
};
const alice = new Person('Alice');
const bob = new Person('Bob');
alice.greet();
delete Person.prototype.greet;
bob.greet();
Person.prototype.greet = function() {
console.log('Hi, I am ' + this.name);
};
alice.greet();What will be the output?
const parent = {
value: 10,
increment: function() {
this.value++;
}
};
const child = Object.create(parent);
console.log(child.value);
child.increment();
console.log(child.value);
console.log(parent.value);
child.value = 20;
console.log(child.value);
console.log(parent.value);What will be the output?
console.log('1');
async function async1() {
console.log('2');
await async2();
console.log('3');
}
async function async2() {
console.log('4');
}
async1();
new Promise(resolve => {
console.log('5');
resolve();
}).then(() => {
console.log('6');
});
setTimeout(() => {
console.log('7');
}, 0);
console.log('8');What will be the output?
console.log('Start');
setTimeout(() => {
console.log('Timeout 1');
}, 0);
Promise.resolve()
.then(() => {
console.log('Promise 1');
return Promise.resolve();
})
.then(() => {
console.log('Promise 2');
});
Promise.resolve()
.then(() => {
console.log('Promise 3');
})
.then(() => {
console.log('Promise 4');
});
setTimeout(() => {
console.log('Timeout 2');
}, 0);
console.log('End');What will be the output?