Kiểu dữ liệu nguyên thủy là các giá trị đơn giản không có phương thức hoặc thuộc tính. Các kiểu này bao gồm:
Number
let age = 25; let price = 19.99;
String
'
) hoặc dấu nháy kép ("
).let name = "Alice"; let greeting = 'Hello, World!';
Boolean
true
hoặc false
.let isLoggedIn = true; let isAdult = false;
Undefined
let uninitializedVariable; console.log(uninitializedVariable); // In ra "undefined"
Null
let emptyValue = null;
Symbol
(ES6)const uniqueSymbol = Symbol('description');
BigInt
(ES11)Number
.const bigIntValue = BigInt(123456789012345678901234567890);
Kiểu dữ liệu tham chiếu chứa các giá trị phức tạp hơn và có thể có phương thức và thuộc tính. Các kiểu này bao gồm:
Object
let person = { name: "Alice", age: 25, isStudent: false };
Array
let fruits = ["apple", "banana", "cherry"];
Function
function greet(name) { return `Hello, ${name}!`; }