Logo
Primitive and Non Primitive data types
Overview

Primitive and Non Primitive data types

October 22, 2025
3 min read

1. Primitive Datatypes

Primitive types are the basic building blocks of JavaScript.
They are simple, immutable values — meaning they don’t hold references or complex structures.
Each primitive directly represents a single value.
Primitive types include:

  • Number
  • String
  • Boolean
  • Undefined
  • Null
  • BigInt
  • Symbol

💡 F*un fact: *When you copy a primitive, you’re copying the actual value, not a reference.
Example:

let a = 10;
let b = a; // b gets a copy of the value 10
b = 20;
console.log(a); // 10 (unchanged)

undefined vs null

Conceptundefinednull
MeaningAutomatically assigned to a variable that’s declared but not initializedIntentionally assigned to represent “no value”
Typeundefinedobject*(a legacy bug in JS)*
BehaviorJavaScript sets it by defaultDeveloper sets it explicitly
Examplelet a; console.log(a) → undefinedlet a = null; console.log(a) → null

💡 I**n short:

  • undefined → “I haven’t been given a value yet.”
  • null → “I’ve been deliberately emptied.”

Number vs BigInt

FeatureNumberBigInt
Description64-bit floating-point numberArbitrary-precision integer
Range±(2⁵³ − 1)Limited only by memory
UsageEveryday calculationsHuge integer values
Examplelet x = 42;let big = 42n;

⚠️ Note: You can’t mix them directly.

10n + 10; // ❌ TypeError

Symbol

A Symbol creates a unique, immutable identifier every time it’s called — even with the same description.

Symbol('id') === Symbol('id'); // false

Used for hidden or private object keys that don’t appear in normal enumeration.

const meta = Symbol('meta');
const user = { name: 'Alice' };
user[meta] = { lastUpdated: 'today' };
console.log(Object.keys(user)); // ['name']
console.log(user[meta]); // { lastUpdated: 'today' }

2. Non-Primitive Datatypes

Non-primitive types are also known as reference types because they don’t store the actual value — they store a reference to where the value lives in memory.
They can hold complex structures and collections of data.
They’re more flexible and can store multiple values under one variable.
Non-primitive types include:

  • Object
  • Array (which is actually a special kind of object)

💡 R*emember: *When you copy or compare non-primitives, you’re dealing with references, not values.
Two objects with identical content are not equal because they live in different memory locations.
Example:

let user1 = { name: "Alice" };
let user2 = user1; // both point to the same memory reference
user2.name = "Bob";
console.log(user1.name); // "Bob" (because they share the same reference)

In short:

TypeStored AsCopy BehaviorExample
PrimitiveActual valueCreates a new copylet b = a
Non-PrimitiveMemory referenceShares the same referencelet obj2 = obj1