How To Use Object Methods in JavaScript?

In JavaScript, The objects can also have methods and these object methods are the actions that can be performed on objects and these actions are stored in the properties as a function definitions.

Example:


<!DOCTYPE html>
<html>
<body>
<h2>Objects</h2>
<p>An object is a function definition, stores property value.</p>
<p id="darkweb"></p>
<script>
// Create an object:
var person = {
  firstName: "Rob",
  lastName : "Alb",
  id     : 4885,
fullName : function() {
    return this.firstName + " " + this.lastName;
  }
};
// Display data from the object:
document.getElementById("darkweb").innerHTML = person.fullName();
</script>
</body>
</html>

The object methods work for array, math functions, boolean, and for more that we will learn in upcoming javascript tutorials.

Stay in touch. Ask Questions.
Lean on us for help, strategies and expertise.

Leave a Reply

Your email address will not be published. Required fields are marked *