JS: Object Overview

By Xah Lee. Date: . Last updated: .

Object syntax basics

What is object

A JavaScript Object is a collection of key-and-value pairs. e.g. {a:1, b:2}. Each key-and-value pair is called a Property.

Data object and special-purpose object

JavaScript objects can be categorized into 2 kinds:

Data object

collection of key-and-value pairs. e.g. {a:1, b:2}

also known as Object Object.

Special-purpose object
  • Special purpose and may have internal data.
  • For example, function, date, regex, etc, are specialized objects.
  • They have special properties and behaviors.
  • But they still have the feature of holding key-and-value pairs.

Prototype of an object (parent of an object)

Is extensible

Each object may be made non-extensible, meaning, you cannot add properties to it.

Source of object

It is useful to distinguish objects by where they came from. We have the following sources:

Standard Object

Objects from the JavaScript language. e.g. arrays, functions, dates, regex, etc.

Hosted Object

Objects from the hosting environment. e.g. in Browser, there's Browser's Window Object. In deno, there is deno object, with properties such as version etc.

User-defined Object