Edit This Code:
<!DOCTYPE html>
<html>
<body>

<p>Creating and using an object method.</p>

<p>An object method is stored as a function definition,
in an object property.</p>

<p id="demo"></p>

<script>
var person = {
    firstName: "John",
    lastName : "Doe",
    id       : 5566,
    fullName : function() {
       return this.firstName + " " + this.lastName;
    }
};

document.getElementById("demo").innerHTML = person.fullName();
</script>
</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy