Predict Array map Output
Predict Output Medium
Question
What does this code print?
Code
const nums = [1, 2, 3];
const doubled = nums.map(n => n * 2);
console.log(doubled);
Hint
map creates a new array by applying the function to each element.
Explanation
map applies the function n => n * 2 to each element: 1*2=2, 2*2=4, 3*2=6. The result is a new array [2, 4, 6]. The original array is unchanged. console.log prints: [2, 4, 6]
Related Resources
Related Lessons
- Arrays
Learn how arrays store ordered lists of values.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.