JS: Property Overview

By Xah Lee. Date: . Last updated: .

A JavaScript object is a set of key/value pairs. Each pair is called a “property”.

[see JS: Object Overview]

2 Kinds of Properties

There are 2 kinds of properties.

  1. Data property → This is the property most of us are familiar with, and is the property used in 99% of code.
  2. Accessor property → Also known as Getter/Setter property. Accessor property generates its value dynamically when being accessed or set. (it calls a function implicitly).

[see JS: Getter/Setter Properties]

Property Attributes

Each JavaScript property has associated info called attribute.

For Data Property, the attributes are: {value, writable, enumerable, configurable}.

For Accessor Property:

[see JS: Property Attributes, writable, enumerable, configurable]

Own Property and Inherited Property

A property can be said to be a object's “own property” or “inherited property”.

When a property is looked up (For example, x.color), JavaScript look at the object to see if it has that property, if not, it lookup its parent, and repeat, until a property is found or a parent is null. This is the technical meaning of inheritance.

[see JS: Prototype and Inheritance]

This is the most important thing about properties. The behavior of many operations on properties, such as {accessing, setting, deleting, “for … in” loop, checking existence, …}, depend on whether the property is the object's own property.

[see JS: Check Property Existence]

When writing to a property or deleting a property, parent object is never touched. Only when reading property, the prototype chain (parents) is looked up.

[see JS: Get Property, Set Property]

Property Key Datatype, Property Value Datatype

Property key can be type string or type symbol. [see JS: Property Key]

Property value can be any type. [see JS: Value Types]

When a property value is a function, that property is often called a “method”.

Dot Notation and Bracket Notation

There are 2 syntax to access a object's property:

[see JS: Property Dot Notation / Bracket Notation]

Add / Remove Property

Property can be added or removed from object.

[see JS: Create/Delete Property]

[see JS: Prevent Adding Property]

Accessing (Reading, Writing, Listing, Check Existence) of Property

Property value can be changed anytime (unless the attribute “configurable” is false).

You can also check if a property exists for a object, in its parents, or list a object's own properties. See:

JS Object Property

  1. Property Overview
  2. Property Key
  3. Dot vs Bracket Notation
  4. Create/Delete Property
  5. Get/Set Property
  6. Check Property Existence
  7. Access Property
  8. List Properties
  9. Property Attributes
  10. Getter/Setter
  11. Property Descriptor
  12. Symbol
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS Basics
  4. JS in Depth
  5. JS Reference
  6. DOM
  7. SVG
  8. JS Misc