Sitemap
Saurabhhavaldar

Saurabhhavaldar

Press enter or click to view image in full size

Data Types in JavaScript

2 min readMar 7, 2026

--

I will try to make you understand all about the Data Types in JavaScript in very easy words.
In any programming language, we need data types — without them, we cannot store even a single value in a machine.
That’s why data types exist: they tell the computer what kind of data we are working with and how it should be handled.

What Is a Data Type?

When you want to store something in memory — like an age, a name, a boolean value, or even a collection of information — you need a data type.
A data type defines the nature of the data and how the JavaScript engine should process it.

Types of Data in JavaScript

JavaScript has two main categories of data types:

  1. Primitive Data Types
  2. Non-Primitive (Reference) Data Types

Understanding Primitive and Non-Primitive

Let’s clarify what these terms mean.

  • Primitive Data Types are the basic building blocks of data in JavaScript.
    They represent simple values like numbers, strings, and booleans.
    Primitive values are immutable, meaning you cannot change the actual value itself — you can only replace it with a new value.
  • Non-Primitive Data Types (also called Reference Types) are complex structures like objects, arrays, and functions.
    These can hold multiple values and are mutable, meaning you can change their contents over time.

In Simple Words

Primitive Data Types are simple, single values that cannot be changed directly. They include
Number, String, Boolean, Null, Undefined, Symbol, and BigInt.
These represent basic pieces of information like numbers, text, or true/false values.

Get Saurabhhavaldar’s stories in your inbox

Join Medium for free to get updates from this writer.

Non-Primitive Data Types, also known as Reference Types, are more complex structures that can hold multiple values or collections of data.
They include Object, Array, Function, Date, Map, and Set.
These are used when you need to group related information together or represent more advanced data relationships.

Quick Example

// Primitive
let age = 25; // Number
let name = "Alice"; // String
let isAdmin = true; // Boolean
// Non-Primitive
let user = { name: "Alice", age: 25 }; // Object
let numbers = [1, 2, 3, 4]; // Array

Key Difference

  • Primitive: Stored by value — copying creates a new independent value.
  • Non-Primitive: Stored by reference — copying creates a reference to the same data.

Example:

// Primitive
let a = 10;
let b = a;
b = 20;
console.log(a); // 10 (unchanged)
// Non-Primitive
let obj1 = { name: "Alice" };
let obj2 = obj1;
obj2.name = "Bob";
console.log(obj1.name); // "Bob" (same reference)

--

--