What is a javascript method?



  • Note: On searches, There are a number different variations of the answer.

    A method is a function assigned to an object property. JavaScript methods are actions that can be performed on objects.

    Using the let keyword to create an object literal with two properties, name and age. Next we have a function that is the property of the object profile.greeting. Here profile is the object and greeting is the method

    let profile = {
      name: "Suzie",
      age: 30
    };
    
    profile.greeting = function() {
      console.log("Hello!");
    };
    
    profile.greeting();
    

    javascript_terminology.png

    Result is:

    Hello!
    


© Lightnetics 2024