Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript Nested Object</h1> <p id="p1"></p> <p id="p2"></p> <script> var firstName = "James"; var lastName = "Bond"; var person = { firstName, lastName } document.getElementById("p1").textContent = person.firstName; document.getElementById("p2").textContent = person.lastName; </script> </body> </html>
Result: