JavaScript Object Syntax

In this article, I’ll explain objects in JavaScript.
Creating Objects
Accessing Properties
  1. JavaScript provides two notations for accessing object properties.
    • Dot Notation
    • Bracket Notation
  2. The first, and most common, is known as dot notation.
  3. Under dot notation, a property is accessed by giving the host object’s name, followed by a period (or dot), followed by the property name.
  4. If object.abhi initially held the value ten, then its value would become eleven after executing this statement.
  5. Note that if an object.abhi did not already have a value, then it would be undefined.
    1. object.abhi = object.abhi+ 1;
  6. The alternate syntax for accessing object properties is known as bracket notation.
  7. In bracket notation, the object name is followed by a set of square brackets. Inside the square brackets, the property name is specified as a string.
    For example
    1. object["abhi"] = object["abhi"] + 1;
Accessing Nested Properties
Functions as Methods