A data type defines what kind of value a variable can hold. JavaScript is a dynamically typed language, meaning you don’t need to specify data types explicitly.

1. Categories of JavaScript Data Types

JavaScript data types are divided into two main categories:

  1. Primitive Data Types

  2. Non-Primitive (Reference) Data Types

2. Primitive Data Types

Primitive types store single, immutable values.

i.String

Represents text data.

let name = "John";
let city = 'Dhaka';

✔ Strings can use single or double quotes

ii.Number

Represents integer and floating-point numbers.

let age = 25;
let price = 99.99;

Special Number values:

let x = Infinity;
let y = NaN; // Not a Number

iii.Boolean

Represents true or false.

let isLoggedIn = true;
let isAdmin = false;

iv.Undefined

A variable that is declared but not assigned a value.

let value;
console.log(value); // undefined

v.Null

Represents intentional absence of value.

let data = null;

typeof null returns "object" (JavaScript bug)

vi.BigInt (ES2020)

Used for very large integers.

let bigNumber = 12345678901234567890n;

vii.Symbol (ES6)

Used for unique identifiers.

let id = Symbol("id");

3. Non-Primitive (Reference) Data Types

Reference types store multiple values or complex structures.

i.Object

Stores data in key-value pairs.

let user = {
name: "John",
age: 25,
isAdmin: true
};

ii.Array

Stores multiple values in a list.

let fruits = ["Apple", "Banana", "Mango"];

iii.Function

Functions are also objects in JavaScript.

function greet() {
return "Hello";
}

iv.Date

Represents date and time.

let today = new Date();

4. typeof Operator

Used to check the data type.

typeof "Hello";      // string

typeof 25;           // number

typeof true;         // boolean

typeof undefined;    // undefined

typeof null;         // object ❌

typeof {};           // object

typeof [];           // object

typeof function(){}; // function

5. Primitive vs Reference Types (Key Difference)

Primitive Types:

  • Stored by value
  • Changes do not affect original value
let a = 10;
let b = a;
b = 20;console.log(a); // 10

Reference Types:

  • Stored by reference
  • Changes affect original object
let obj1 = { value: 10 };
let obj2 = obj1;obj2.value = 20;
console.log(obj1.value); // 20

6. Type Conversion (Type Casting)

String to Number

Number("10"); // 10

Number to String

String(100); // "100"

Boolean Conversion

Boolean(0);    // false
Boolean(1);    // true

7. Dynamic Typing Example

let data = "Hello";
data = 100;
data = true;

✔ JavaScript allows changing data type at runtime.

Categorized in:

Javascript,