1. What is the output?
[1, 2, 3].forEach(num => num * 2);
Options:
A) [2, 4, 6]
B) undefined
C) [1, 2, 3]
D) Error
✅ Answer: B) undefined
Explanation:
forEach() does NOT return anything → returns undefined
2. What is the output?
let result = [1, 2, 3].map(num => {
if (num > 1) return num * 2;
});
console.log(result);
Options:
A) [2, 4, 6]
B) [undefined, 4, 6]
C) [4, 6]
D) Error
✅ Answer: B) [undefined, 4, 6]
Explanation:
map() always returns same length
For num = 1, nothing returned → undefined
3. What is the output?
let arr = [1, 2, 3];
let result = arr.filter(num => num > 5);
console.log(result);
Options:
A) [undefined]
B) []
C) null
D) Error
✅ Answer: B) []
Explanation:
No elements match → empty array
4. What is the output?
let result = [1, 2, 3].reduce((acc, val) => acc + val);
console.log(result);
Options:
A) 6
B) 0
C) undefined
D) Error
✅ Answer: A) 6
Explanation:
Default acc = first element = 1
→ 1+2=3 → 3+3=6
5. What is the output?
let arr = [1, 2, 3];
let result = arr.some(num => num > 2);
console.log(result);
Options:
A) true
B) false
✅ Answer: A) true
One element (3) satisfies condition
6. What is the output?
let arr = [2, 4, 6];
let result = arr.every(num => num % 2 === 0);
console.log(result);
Options:
A) true
B) false
✅ Answer: A) true
All elements satisfy condition
7. What is the output?
let arr = [1, 2, 3];
arr.map(num => num * 2);
console.log(arr);
Options:
A) [2, 4, 6]
B) [1, 2, 3]
C) undefined
D) Error
✅ Answer: B) [1, 2, 3]
map() does NOT modify original array
8. What is the output?
let arr = [1, 2, 3];
arr.forEach(num => num * 2);
console.log(arr);
Options:
A) [2, 4, 6]
B) [1, 2, 3]
✅ Answer: B) [1, 2, 3]
forEach doesn’t change array unless you modify directly
9. What is the output?
let arr = [1, [2, 3]];
console.log(arr.flat());
Options:
A) [1, 2, 3]
B) [1, [2,3]]
✅ Answer: A) [1, 2, 3]
10. What is the output?
let arr = [1, 2, 3];
let result = arr.reduce((acc, val) => acc + val, 5);
console.log(result);
Options:
A) 6
B) 11
C) 10
✅ Answer: B) 11
5 + 1 + 2 + 3 = 11
11. What is the output?
console.log([..."hello"]);
Options:
A) "hello"
B) ["h","e","l","l","o"]
✅ Answer: B
12. What is the output?
let arr = [10, 20, 30];
console.log(arr.at(-1));
Options:
A) 10
B) 30
C) undefined
✅ Answer: B) 30
Top comments (0)