Mutable
Có thể thay đổi giá trị bên trong sau khi tạo
Trong JavaScript, Non-primitive (hay Reference types) bao gồm Objects, Arrays, Functions, Date, v.v. Các kiểu dữ liệu này được lưu trữ dưới dạng tham chiếu thay vì giá trị trực tiếp.
Mutable
Có thể thay đổi giá trị bên trong sau khi tạo
So sánh tham chiếu
Hai object giống nhau nhưng khác tham chiếu → KHÔNG bằng nhau
Copy tham chiếu
Khi gán, chỉ copy tham chiếu (cùng trỏ tới 1 object)
Object là kiểu dữ liệu dùng để lưu trữ tập hợp các giá trị dưới dạng cặp key-value (khóa-giá trị). Mỗi đối tượng có thể chứa nhiều thuộc tính (properties) và phương thức (methods).
let person = { name: "Alice", age: 25, greet: function() { console.log("Hello, " + this.name); }};let person = new Object();person.name = "Alice";person.age = 25;console.log(person.name); // "Alice"console.log(person.age); // 25console.log(person["name"]); // "Alice"console.log(person["age"]); // 25person.greet(); // "Hello, Alice"| Nhóm thao tác | Phương thức / Cú pháp |
|---|---|
| Tạo & clone/merge | Literal {}, Object.assign, spread {...a}, structuredClone |
| Đọc/ghi/xoá thuộc tính | Dot obj.x, bracket obj['x'], gán, delete |
| Duyệt | for...in, Object.keys/values/entries |
| Biến đổi nâng cao | Destructuring, rest/spread, computed key [expr] |
| Bất biến & cấu hình | Object.freeze/seal, property descriptors (Object.defineProperty) |
| Kiểm tra & an toàn | in, hasOwn, ?. (optional chaining), ?? (nullish) |
| Prototype & kế thừa | Object.create, Object.getPrototypeOf, isPrototypeOf |
| JSON serialize | JSON.stringify/parse |