Enumerability & Ownership
Learn about property enumerability and ownership in JavaScript.
1. Querying Properties
Different methods can be used to check for the existence of a property on an object.
JavaScript Code
Live JavaScript representation with highlighted changes
const proto = { inherited: 'yes' };const obj = Object.create(proto);obj.own = 'yes';Object.defineProperty(obj, 'nonEnum', { value: 'yes', enumerable: false });console.log(obj.hasOwnProperty("own"));
2. Traversing Properties
JavaScript provides several ways to traverse an object's properties.
JavaScript Code
Live JavaScript representation with highlighted changes
const proto = { inherited: 'yes' };const obj = Object.create(proto);obj.own = 'yes';Object.defineProperty(obj, 'nonEnum', { value: 'yes', enumerable: false });console.log(Object.keys(obj));
Console Output