Programming foundations

Stage 1 · Lesson 7 of 10

References and copying

Your first language

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

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    The language itself, closures and async included, with runnable exercises per lesson

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free: Part 1 is the most complete modern JavaScript tutorial, with tasks per chapter

Practise

  • Small exercises in your language track, with free feedback from a human mentor

  • Foundations path: the JavaScript basics lessons and the exercises repo with tests

Keep handy

  • The JavaScript reference: look up every array and string method here

Mark this stage as not done?