JAVASCRIPT

Object method


An object method is a function that is defined as a property of an object. These methods can be called to perform actions on the object or to retrieve information related to the object.

For Calling object method we use dot notation (object.method()), and the method has access to the object's properties.

 

Example:

// Methods
let person = {
    name: "Rohit",
    age: 25,

    greet: function() {
        return "Hello, my name is " + this.name 
        + " and I am " + this.age + " years old.";
    }
};

console.log(person.greet()); 
// Output: Hello, my name is Rohit and I am 25 years old.

 

Note:

For Calling object method we use dot notation (object.method()), and the method has access to the object's properties. The method has implicit access to the properties and other methods of the object through the `this` keyword.