DEV Community

Mathu varshtih
Mathu varshtih

Posted on

5 Important Points about Objects in JavaScript

  1. Objects are collections of key-value pairs

    An object stores data as properties, where each property has a key (string or Symbol) and a corresponding value (any data type, including other objects or functions).

  2. Objects can be created in multiple ways

    The most common ways are:

    • Object literal: const person = { name: "John", age: 30 };
    • Constructor: const person = new Object();
    • Object.create() method
  3. Properties can be accessed using two notations

    • Dot notation: person.name
    • Bracket notation: person["name"] (useful when the key is dynamic or contains special characters)
  4. Objects are mutable and can hold methods

    You can add, modify, or delete properties at any time.

Top comments (1)

Collapse
 
tracygjg profile image
Tracy Gilmore •

Hi Mathu, 5? I only count four above but what about:

  • Object mutability can be configured using: freeze, seal and preventExtensions.
  • Objects can inherit properties and methods from class-based objects or through the prototype chain.
  • Objects can be stringified into JSON strings, with some restrictions.
  • Objects can be duplicated (deeply) using structureClone.