Courses / React 19: From Components to Production / Chapter 2
Module 1 · Start Here · Chapter 2 of 30
JavaScript for React: Values, Closures, Arrays, Async and the DOM
No prerequisites. Next up: Introduction to React: Elements, JSX and the First Render.
Part 1 · Values, references and equality
Values and references
A FASTag reader at a toll plaza produces a stream of small records, and the code that sums, sorts and shows them is ordinary JavaScript. React leans on a handful of language features so heavily that learning them first removes most of the later confusion.
JavaScript has two kinds of values. Primitives are strings, numbers, booleans, undefined, null, symbols and bigints. They are compared by their content: 60 === 60 is always true. Objects include plain objects, arrays and functions. A variable holding an object holds a reference, an address of that object in memory, and two variables can hold the same address.
Two consequences matter for React. First, === on objects asks "is this the very same object", not "do they look alike". Second, assigning an object to another variable does not copy it, so a change made through one name is visible through the other. React decides whether something changed by comparing references, so you will keep meeting both.
React compares state values, hook dependencies and memoised props with Object.is. A new object with the same contents counts as a change. The same object after you mutated it counts as no change.