Have you heard about Hack Frontend Community?Join us on Telegram!
Practice JS Problems

Primitives vs Non-Primitives in JavaScript: Value vs Reference

What are Primitives and Non-Primitives?

In JavaScript all data is divided into two types:

  • Primitive Types — values that are not objects and have immutable value.
  • Non-Primitive Types (Reference Types) — objects that are stored and passed by reference, can be mutable.

Primitive Types

Primitives are basic types built into the language.

TypeExampleFeatures
string"Hello"Text string
number42, 3.14Any number (integer and floating point)
booleantrue, falseTrue or false
nullnullIntentional absence of value
undefinedundefinedValue wasn't assigned
bigint900719925...nLarge numbers
symbolSymbol('id')Unique identifiers

Primitive Features

  • Immutable — cannot be changed
  • Passed by value — copied when assigned
  • Compared by value

Non-Primitive Types

  • Object
  • Array
  • Function
  • Date, RegExp, etc.

Non-Primitive Features

  • Mutable — can be modified
  • Passed by reference — not copied, reference is passed
  • Compared by reference

Summary:

Primitives are simple, immutable values passed by value. Non-primitives are objects passed by reference.

Practice JS Problems

By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.