Q1. How is a forEach statement different from a for statement?
-
Only a for statement uses a callback function.
-
A for statement is generic, but a forEach statement can be used only with an array.
-
Only a forEach statement lets you specify your own iterator.
-
A forEach statement is generic, but a for statement can be used only with an array.
Answer
2
Reference Differences between forEach and for loop
Q2. When would the final statement in the code shown be logged to the console? When would ‘results shown’ be logged to the console?
let modal = document.querySelector('#result');
setTimeout(function () {
modal.classList.remove('hidden');
}, 10000);
console.log('Results shown');
- after 10 second
- after results are received from the HTTP request
- after 10000 seconds
- immediately
Answer
4
Reference Javascript is synchronous and single threaded