Value Type vs Reference Type — What's the Difference?

A value type stores its actual data directly, and copying it creates an independent duplicate; a reference type stores a reference (pointer) to data held els...

Published November 23, 2026

A value type stores its data directly, so assigning it copies the data; a reference type stores a pointer to the data, so assigning it copies only the pointer and both variables see the same object.

The concept

Primitives (numbers, booleans, strings in JavaScript) behave like values. Objects, arrays and functions are references.

This explains why changing a copied object also changes the original, and why == on objects compares identity.

Copy vs share

let a = 1; let b = a; b = 2 → a is still 1
let o = {n:1}; let p = o; p.n = 2 → o.n is 2

Practical examples

Value

let a = 1
let b = a
b = 2
console.log(a) // 1

Reference

const o = { n: 1 }
const p = o
p.n = 2
console.log(o.n) // 2

Function arguments

function change(obj) { obj.x = 1 }   // mutates caller's object
function reassign(obj) { obj = {} }  // does not affect caller

Make a copy

const copy = structuredClone(o)

Common mistakes

  • Expecting object assignment to copy.
  • Mutating function arguments unintentionally.
  • Comparing objects with ==.

Key takeaways

  • Values copy, references share.
  • Objects/arrays are references.
  • Clone when you need independence.

FAQ

Are strings values or references?

Immutable, so they behave like values.

Languages differ?

C# and Swift have explicit value types (structs); Java has primitives vs objects.

More General articles