Khác nhau ở phạm vi kiểm tra:
- Object.hasOwn(obj, key) / hasOwnProperty: chỉ kiểm tra key nằm trực tiếp trên object.
- key in obj: kiểm tra cả object và prototype chain.
Ví dụ: key được "thừa hưởng" từ prototype thì in là true, nhưng hasOwn là false.
Trong code mới, ưu tiên Object.hasOwn(obj, key).
They differ by scope:
- Object.hasOwn(obj, key) / hasOwnProperty: checks only own properties on the object.
- key in obj: checks both own properties and the prototype chain.
So a key inherited from prototype gives true with in, but false with hasOwn.
In modern code, prefer Object.hasOwn(obj, key).