JavaScript objects and properties

In JavaScript, objects are a fundamental data type that allow you to group related data and behavior together into a single entity. Objects are composed of one or more key-value pairs, where the key is a string (or symbol) and the value can be any JavaScript data type, including other objects.

Here’s an example of an object literal in JavaScript:

let person = {

  name: “John”,

  age: 30,

  address: {

    street: “123 Main St”,

    city: “Anytown”,

    state: “CA”

  },

  sayHello: function() {

    console.log(“Hello, my name is ” + this.name);

  }

};

You can access properties of an object using dot notation or bracket notation.

You can also add or modify properties of an object using dot notation or bracket notation.