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
. Hereprofile
is the object andgreeting
is the methodlet profile = { name: "Suzie", age: 30 }; profile.greeting = function() { console.log("Hello!"); }; profile.greeting();
Result is:
Hello!
© Lightnetics 2024