Data Types in JavaScript


In JavaScript, data types tell the language what kind of value a variable is holding. Understanding data types is super important because it affects how your code behaves.


JavaScript is dynamically typed, so you don’t need to declare a type — the interpreter figures it out for you.

let name = "Alice"; // JavaScript knows this is a string
              

1. Primitive Data Types

Primitive types are the most basic data types. They store single values and are immutable (can’t be changed after creation).

JavaScript Data Types Table
Data Type Example Description String "Hello" Text, always inside quotes Number 42, 3.14 Integer or decimal numbers Boolean true, false Logical values (yes/no, on/off) Undefined let x; A variable that’s declared but not set Null let y = null; Represents no value (empty) BigInt 12345678901234567890n For really big numbers Symbol Symbol("id") Unique value, useful for object keys

2. Non-Primitive (Reference) Data Types

These types store collections or complex structures of data.

JavaScript Data Types Table

JavaScript Data Types


Data Type Example Description Object { name: "John", age: 30 } Collection of key-value pairs Array [1, 2, 3, 4] Ordered list of items Function function greet() {} Block of code that can be reused Date, RegExp Built-in objects Used for specific tasks

type of Operator

Use typeof to find out what data type a variable is:

let age = 25;
console.log(typeof age); // "number"

let user = { name: "Alice" };
console.log(typeof user); // "object"

Examples of Different Data Types


let name = "Alice";           // String
let age = 30;                 // Number
let isLoggedIn = true;        // Boolean
let email;                    // Undefined
let car = null;               // Null
let id = Symbol("unique");    // Symbol
let big = 1234567890123456789n; // BigInt

let colors = ["red", "green"];          // Array
let person = { name: "John", age: 30 }; // Object
function greet() { return "Hi!"; }      // Function