Stage 1 · Lesson 7 of 10
References and copying
Objects and arrays are shared by reference. After const b = a, both names point to the same array, so b.push(4) changes a as well. Numbers, strings and are primitives, simple values that are copied whole.
That is why a that changes an array parameter also changes the caller's array. Make a copy with the , [...a] or {...obj}. Know that this is a : nested arrays and objects inside are still shared.
structuredClone(obj) makes a deep copy of plain data, copying every level. === on objects checks whether two names point to the same object. It does not check whether the contents match, so [1] === [1] is false. The next stage shows what this looks like in memory.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
The language itself, closures and async included, with runnable exercises per lesson
- GuideFreeJavaScript.info
Ilya Kantor
Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter