Mobile development

Stage 1 · Lesson 4 of 9

Immutable updates

JavaScript and TypeScript

React redraws a screen when state changes. It checks for a change by reference: is this the same object as before? If you push to an array or change an object's field in place, the reference stays the same, so the screen may not update.

That is why you always create new values instead, with the and array methods. To add, write [...todos, newTodo]. To remove, write todos.filter((t) => t.id !== id).

To change one item, write todos.map((t) => (t.id === id ? { ...t, done: true } : t)). Spread is shallow: it copies only the top level, so a nested object needs copying at each level you change. Learning this now, in plain , saves days of confused debugging once you add state to components.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    Beginner JavaScript with an exercise after most lessons

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free and thorough: Part 1 is the language, skip the browser chapters in Part 2

Practise

  • Dart, TypeScript, Kotlin and Swift tracks with small exercises and free mentor feedback

Keep handy

Also worth your time

Mark this stage as not done?