I was asked this question in an interview yesterday, on how to change the code so that it gives the expected output. I got a hint that await can be used before callMe(delay) function.
function callMe(delay) {
setTimeout(() => {
console.log('Called');
}, delay);
}
const delays = [500, 1000, 1500];
for (let delay of delays) {
callMe(delay);
}
console.log('Completed');
//## Expected Output -
// Called
// Called
// Called
// Completed
This question has been bothering me a lot. Thanks in advance.