HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

JavaScript Data Types

Written by RedoHub Team · Last updated: August 1, 2026

Data types describe the different kinds of data that we can work with and store in variables. In JavaScript, there are eight basic data types, which are divided into two categories: Primitive and Object (Reference) types.


The Concept of Dynamic Typing

JavaScript is a "dynamically typed" language. This means you don't have to declare the type of data a variable will hold, and the same variable can hold different types of data at different times.

let x;           // x is currently undefined
x = 5;           // x is now a number
x = "Mim";       // x is now a string 

1. Primitive Data Types

Primitive values are single pieces of data. They are immutable (cannot be changed). There are 7 primitive types in JavaScript:

String

Textual data wrapped in quotes.
Ex: "Hello"

Number

Integers and decimals.
Ex: 42, 3.14

Boolean

Logical values.
Ex: true, false

Undefined

A variable that has not been assigned a value.

Null

Represents an intentional "empty" or "nothing" value.

BigInt

Very large integers beyond the limit of Number type.

Symbol

Unique and immutable values used as object keys.


2. Non-Primitive (Reference) Type

There is only one non-primitive type in JavaScript: The Object.

Objects can store collections of data and more complex entities. Common objects you will use include:

  • Regular Objects{ name: "Mim", age: 25 }
  • Arrays[1, 2, 3, 4]
  • Datesnew Date()

Why Knowing Data Types is Important

When you use operators like +, JavaScript behaves differently based on the data type:

let x = 5 + 5;       // Result is 10 (Addition)
let y = "5" + 5;     // Result is "55" (Concatenation)
let z = "5" + "5";   // Result is "55" (Concatenation)
Note: JavaScript usually evaluates expressions from left to right. If a string is involved in an addition, the entire result often becomes a string.

Key Points to Remember

  • JavaScript variables can hold any data type (dynamic typing)
  • There are 7 primitive types: string, number, bigint, boolean, undefined, null, symbol
  • There is 1 non-primitive type: Object
  • Arrays and Dates are specific types of objects
  • Types matter when performing calculations and joining data

Common Mistakes to Avoid

Assuming typeof null is "null". It actually returns "object" — a decades-old JavaScript quirk that trips up beginners checking for null with typeof. Use value === null instead.
Checking for NaN with === NaN. NaN === NaN is always false — NaN is the only value that isn't equal to itself. Use Number.isNaN(value) to test for it correctly.
Using == instead of ===. Loose equality performs type coercion, so "0" == false is true even though they're different types. Strict equality (===) avoids these surprises.

Try It: typeof Quirks

Run this in your browser console to see the well-known type quirks for yourself:

console.log(typeof null);        // "object"  (the famous quirk)
console.log(typeof undefined);   // "undefined"
console.log(typeof NaN);         // "number"  (NaN is technically a Number)
console.log(NaN === NaN);        // false
console.log(Number.isNaN(NaN));  // true

Frequently Asked Questions

Q: Why does typeof null return "object"?

A: It's a bug from JavaScript's first version in 1995 that's been kept ever since for backward compatibility — fixing it now would break too much existing code on the web.

Q: What's the difference between null and undefined?

A: undefined means a variable was declared but never given a value. null is an intentional "no value" that a developer assigns on purpose.

Q: How do I check if two values are of the same type?

A: Compare typeof valueA === typeof valueB for primitives. See the MDN typeof reference for how it behaves across every data type.