JavaScript Data Types: Complete Guide
with Examples
JavaScript is a dynamically typed language, meaning variables can hold different
types of values at different times. Understanding JavaScript data types is
fundamental for writing effective code. JavaScript provides several built-in data
types, categorized into primitive types and objects.
The following table below provides a summary of the different JavaScript data
types, their descriptions, and examples.
Data Description Example
Type
String Represents textual data let name = "John";
Number Represents numeric let age = 30;
values (both integer and
floating-point)
Boolean Represents logical let isActive = true;
values: true or false
Null Represents an intentional let emptyValue = null;
absence of any object
value
Undefined Indicates that a variable let value;
has not been assigned a
value
Symbol Represents a unique and let symbol = Symbol('description');
immutable value
BigInt Represents integers with let bigIntValue =
1234567890123456789012345678901234567890n;
arbitrary precision
Object Represents collections of let person = { name: 'John', age: 30 };
properties
Array Represents ordered let numbers = [1, 2, 3, 4, 5];
collections of values
Data Description Example
Type
Function Represents reusable function greet() { return "Hello"; }
blocks of code
JavaScript data types are categorized into two main types: primitive and non-
primitive (also known as reference) types.
Primitive data types include String, Number, Boolean, Null, Undefined, Symbol,
and BigInt. Non-primitive data types include Object, Array, and Function.
Primitive Data Types
Primitive data types are the most basic data types in JavaScript. They include:
1. String
Strings represent text and are created using single quotes, double quotes, or
backticks for template literals.
let greeting = 'Hello, World!';
let name = "John Doe";
let message = `Hello, ${name}!`; // Template literal
2. Number
Numbers represent both integer and floating-point values. Integers are whole
numbers, while floating-point numbers have decimals.
let age = 30; // Integer
let pi = 3.14; // Floating-point
let largeNumber = 1e6; // 1000000 (Scientific notation)
3. Boolean
Booleans represent logical values: true or false.
let isActive = true;
let isComplete = false;
4. Null
Null represents an intentional absence of any object value.
let emptyValue = null;
5. Undefined
Undefined means a variable has been declared but not assigned a value.
let undefinedValue;
[Link](undefinedValue); // undefined
6. Symbol
Symbols are unique and immutable values, often used to identify object
properties uniquely.
let symbol1 = Symbol('description');
let symbol2 = Symbol('description');
[Link](symbol1 === symbol2); // false
7. BigInt
BigInt is used for integers that are too large to be represented by the Number
type.
let bigIntValue = 1234567890123456789012345678901234567890n;
[Link](bigIntValue); // 1234567890123456789012345678901234567890n
Object Data Types
Objects are collections of properties, and they include more complex data
structures such as arrays and functions.
1. Object
Objects are collections of key-value pairs.
let person = {
name: 'John',
age: 30
};
[Link]([Link]); // John
2. Array
Arrays are ordered collections of values.
let numbers = [1, 2, 3, 4, 5];
[Link](numbers[0]); // 1
3. Function
Functions are reusable blocks of code.
function greet(name) {
return `Hello, ${name}!`;
}
[Link](greet('Alice')); // Hello, Alice!