JS Basic Tutorial
JS Basic Dom
JS Reference
JavaScript has two main categories of data types: Primitive and Non-Primitive (Reference types).
Primitive data types are immutable and stored directly in memory.
Data Type |
Description |
Example |
|---|---|---|
|
String |
Represents text enclosed in quotes. |
let name = "john"; |
|
Number |
Represents numeric values (integer or float). |
let age = 25; |
|
BigInt |
Represents large integers beyond |
let bigNum = 12345678901234567890n; |
|
Boolean |
Represents true or false values. |
let isActive = true; |
|
Undefined |
A variable declared but not assigned a value. |
let x; |
|
Null |
Represents an intentional absence of value. |
let data = null; |
|
Symbol |
Represents unique and immutable identifiers. |
let id = Symbol('id'); |
Non-primitive types are mutable and stored as references in memory.
Data Type |
Description |
Example |
|---|---|---|
|
Object |
A collection of key-value pairs. |
let obj = {name: "John"}; |
|
Array |
A list-like structure for storing multiple values. |
let arr = [1, 2, 3]; |
|
Function |
A block of reusable code. |
function greet() { console.log('Hello'); } |
|
Date |
Represents dates and times. |
let date = new Date(); |
JavaScript is dynamically typed, meaning variables can hold values of any type.
To check a variable's data type, use the typeof operator: