Same array or a copy?
b is the same array as a. c, d, e and f are new arrays. Two arrays with equal contents are still not ===.
Assigning an array to another variable copies only the reference, so both names point at the same array; spread, slice and Array.from make a shallow copy (a new outer array sharing the same inner objects), and structuredClone makes a deep copy where nothing is shared.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Make a copy of const prices = [10, 20, 30]; that you can sort descending without changing prices, in two different ways.
Given const users = [{ id: 1, active: false }, { id: 2, active: false }];, return a new array where user 2 is active, without changing users, and prove it.
Explain it without notes
What is the difference between a shallow copy and a deep copy of an array?
Why does [1, 2] === [1, 2] return false?
What can structuredClone copy that JSON.parse(JSON.stringify()) can't, and what can't it copy?
How do you update one object inside an array without mutating the original array?
Console
(nothing was printed)Expected console output
[ 1, 2, 3, 4 ] true
[ 1, 2, 3, 4 ] [ 1, 2, 3, 4, 5 ] false
false
[ 1, 2, 3, 4 ] [ 1, 2, 3, 4 ] [ 1, 2, 3, 4 ]