JavaScript for React — visual mental model
React is a JavaScript library. Before memorising React APIs, build the JavaScript models that React code depends on.
Data
objects · arrays · destructuring · spread
Transformation
map · filter · find · reduce · derived values
Functions
callbacks · closures · scope · modules
Identity
primitive values · references · object equality
Async
Promises · async/await · event-loop basics
Expressions
ternaries · logical operators · optional chaining · nullish coalescing
Arrays become UI
Array of domain data
productsTransform data into element descriptions
products.map(product => <ProductCard ... />)Visible list
Each item becomes part of the component tree.
Immutable updates
MutationChange the existing value
items.push(newItem) keeps the same array object and modifies it in place.
Immutable updateCreate the next value
[...items, newItem] creates a new array while the previous snapshot stays intact.
Reference identity
Primitive value
5 === 5 → trueObject reference
{} === {} → falseEffects
dependency identity
Context
provider value identity
Memoization
memo/useMemo/useCallback
External stores
selector result identity
Closures and render snapshots
1Render starts
2Props/state values exist for this render
3Handlers/functions are created
4Functions close over those values
5Later callback runs with that closure
Async work
Current JavaScript runs
Promise represents a future result
pending → fulfilled or rejected
Continuation becomes eligible later
await pauses the async function, not the entire JavaScript runtime.Which JavaScript tool fits?
What are you trying to do?
Render one UI item for every array item?map
Keep only matching items?filter
Find one matching item?find
Calculate a total or aggregate?reduce or a clearer dedicated operation
Copy while changing an object/array?spread + immutable update
Run code later after another operation?callback / Promise / async function
Reuse code across files?ES modules
Keep this picture in your head
JavaScript values + functions
React components use those values to describe UI
React adds rendering, state, identity, and lifecycle semantics
Continue with the detailed JavaScript for React chapter for the complete examples, edge cases, closures, promises, modules, and event-loop explanation.