x
<html>
<body>
<h2>JavaScript Object Methods</h2>
<p>Object data can be accessed using property stored as a function.</p>
<p id="demo"></p>
<script>
// Create an object:
const person = {
firstName: "John",
lastName: "Doe",
fullName: function() {
return this.firstName + " " + this.lastName;
}
};
// Display data from the object using a method:
document.getElementById("demo").innerHTML = person.fullName();
</script>
</body>
</html>