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:
Numberlet age = 25; let price = 19.99;
String') hoặc dấu nháy kép (").let name = "Alice"; let greeting = 'Hello, World!';
Booleantrue hoặc false.let isLoggedIn = true; let isAdult = false;
Undefinedlet uninitializedVariable; console.log(uninitializedVariable); // In ra "undefined"
Nulllet 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:
Objectlet person = {
name: "Alice",
age: 25,
isStudent: false
};
Arraylet fruits = ["apple", "banana", "cherry"];
Functionfunction greet(name) {
return `Hello, ${name}!`;
}