Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript Object</h1> <p id="p1"></p> <p id="p2"></p> <p id="p3"></p> <p id="p4"></p> <p id="p5"></p> <script> var person = { firstName: "James", lastName: "Bond", age: 25, getFullName: function () { return this.firstName + ' ' + this.lastName } }; document.getElementById("p1").innerHTML = person.firstName; document.getElementById("p2").innerHTML = person.lastName; document.getElementById("p3").innerHTML = person["firstName"]; document.getElementById("p4").innerHTML = person["lastName"]; document.getElementById("p5").innerHTML = person.getFullName(); </script> </body> </html>
Result: