All quizzesHard
Advanced Output Traps — Series 2
Preview — 3 of 10 questions
What is the output?
javascript
const arr = [1, , 3];
let forEachCount = 0;
arr.forEach((item) => {
forEachCount++;
});
let forLoopCount = 0;
for (let i = 0; i < arr.length; i++) {
forLoopCount++;
}
console.log(forEachCount);
console.log(forLoopCount);
console.log(arr[1]);A3, 3, undefined
B2, 2, undefined
C2, 3, undefined
D3, 3, 3
What is the output?
javascript
const proto = {
get value() {
return 42;
},
};
const obj = Object.create(proto);
function trySet() {
'use strict';
obj.value = 100;
}
try {
trySet();
} catch (e) {
console.log(e instanceof TypeError);
}
console.log(obj.value);Afalse, 100
Btrue, 100
Cfalse, 42
Dtrue, 42
What is the output?
javascript
const items = ['a', 'b', 'c'];
const log = [];
for (const item of items) {
setTimeout(() => log.push(item), 0);
}
setTimeout(() => console.log(log), 10);A[]
B["a", "b", "c"]
C["c", "c", "c"]
D["c", "b", "a"]
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.