In this series, i will share the questions for practice in JS.
1. Given the following code. what will be the output
const obj = {
name: 'shashank',
address: {
city: 'xyz'
}
};
const a = {...obj};
a.address.city = 'delhi'
console.log(obj.address.city); // what is the output
JavaScriptOutput:
delhi
2. Given the following code. What will be the output
console.log('start')
setTimeOut(() => {
console.log('setTimeout');
}, 0);
Promise.resolve().then(() => {
console.log('Promise');
});
console.log('end');
process.nextTick(() => console.log('ok');
JavaScriptOutput
Start
End
ok
Promise
setTimeout
3. Given the following code, what will be the output
for (var i = 0; i < 4; i++) {
setTimeout(() => console.log(i), 0);
}
JavaScriptOutput:
4
4
4
4