JavaScript Advanced Array Methods (map, filter, reduce) Quiz
Answer 35 questions that dive into map transformations, filter logic, reduce accumulations, callback signatures, immutability, chaining, patterns, performance trade-offs, and behavior comparisons.
Question 1
What does Array.prototype.map return?
Question 2
Which use case best fits map?
Question 3
What prints?
const nums = [1, 2, 3]
const doubled = nums.map(n => n * 2)
console.log(nums)
console.log(doubled)Question 4
Why is map often preferred over forEach plus push?
Question 5
What prints?
const arr = [1, , 3]
const result = arr.map(x => x ?? 0)
console.log(result.length)Question 6
What does Array.prototype.filter expect from its callback?
Question 7
Why is filter considered non-destructive?
Question 8
What prints?
const words = ['apple', 'banana', 'pear']
const short = words.filter(w => w.length <= 5)
console.log(short)Question 9
Which scenario favors filter?
Question 10
What prints?
const data = [0, 1, 2, 3]
const truthy = data.filter(Boolean)
console.log(truthy)Question 11
What does Array.prototype.reduce return?
Question 12
What prints?
const nums = [1, 2, 3]
const sum = nums.reduce((acc, n) => acc + n, 0)
console.log(sum)Question 13
Why is the initial accumulator value important?
Question 14
What prints?
const letters = ['a', 'b', 'c']
const joined = letters.reduce((acc, cur) => acc + cur)
console.log(joined)Question 15
When should reduce be avoided?
Question 16
What is the parameter order for map/filter/reduce callbacks?
Question 17
How many arguments can reduce callbacks receive?
Question 18
What prints?
const nums = [10, 20]
nums.map((value, index, array) => {
if (array === nums && index === 1) {
console.log(value)
}
})Question 19
Why is using the index parameter helpful?
Question 20
What prints?
const arr = ['x', 'y', 'z']
const labeled = arr.map((value, index) => `${index}:${value}`)
console.log(labeled)Question 21
Why should map/filter callbacks stay pure?
Question 22
How can you ensure immutability when mapping objects?
Question 23
What prints?
const items = [{ count: 1 }, { count: 2 }]
const doubled = items.map(item => ({ ...item, count: item.count * 2 }))
doubled[0].count = 99
console.log(items[0].count)Question 24
Why is mutating the array inside a map callback discouraged?
Question 25
How does reduce help maintain immutability?
Question 26
What prints?
const result = [1, 2, 3, 4]
.filter(n => n % 2 === 0)
.map(n => n * 10)
console.log(result)Question 27
Why is chaining map/filter/reduce powerful?
Question 28
What prints?
const pipeline = [
{ price: 5, inStock: true },
{ price: 12, inStock: false },
{ price: 8, inStock: true }
]
const total = pipeline
.filter(item => item.inStock)
.map(item => item.price)
.reduce((sum, price) => sum + price, 0)
console.log(total)Question 29
When chaining multiple methods, what helps readability?
Question 30
What prints?
const names = ['Ada', 'Grace', 'Linus']
const sentence = names
.map(name => name.toUpperCase())
.join(', ')
console.log(sentence)Question 31
Which pattern suits reduce well?
Question 32
Why does map produce the same number of items as the original array?
Question 33
What prints?
const scores = [40, 80, 90, 55]
const passing = scores.filter(score => score >= 60).length
console.log(passing)Question 34
Which statement contrasts map vs reduce?
Question 35
How does filter differ from map regarding side effects?
