Struct Vs Class When To Use Which

1 min read
Rapid overview

Value vs Reference in JavaScript

Use this guide to explain how primitives and objects behave in JavaScript.


Value types (primitives)

  • string, number, boolean, bigint, symbol, null, undefined.
  • Copied by value.

Reference types

  • Objects, arrays, functions.
  • Assigned by reference; mutations affect all references.
const original = { count: 1 };
const alias = original;
alias.count = 2;
// original.count === 2

When it matters

  • React state updates rely on immutable copies.
  • Avoid unintended mutation in shared references.

Interview prompt

  • Explain how to update nested state without mutation.