Map Always Returns a New Array
What you'll learn: You'll understand why map() never changes the original array and always creates a fresh one of identical length.
The Core Idea
When you call map() on an array, JavaScript always creates and returns a brand new array. The original array remains completely untouched. This happens even if your callback function returns the exact same values—map() still builds a new container.
Think of it like photocopying documents: no matter what you write on the copies, the originals stay pristine in the filing cabinet.
Why This Matters
const numbers = [1, 2, 3];
const doubled = numbers.map(num => num * 2);
console.log(numbers); // [1, 2, 3] - unchanged
console.log(doubled); // [2, 4, 6] - new array
console.log(numbers === doubled); // false - different arrays
Even when values stay the same:
const values = [5, 10, 15];
const same = values.map(v => v); // Just returns each value as-is
console.log(values === same); // false - still a new array!
Same Length, Always
The new array has exactly the same number of elements as the original. Map doesn't filter or skip—it transforms one-to-one:
const letters = ['a', 'b', 'c'];
const upper = letters.map(letter => letter.toUpperCase());
console.log(upper.length === letters.length); // true - always matched
This predictability makes map() safe for data transformations without side effects.
Key Takeaway: map() is non-mutating—it always produces a new array of the same length, leaving the original array completely unchanged. This immutability makes your code safer and more predictable.