Home
<!DOCTYPE html> <html> <body> <h1>Demo: JavaScript Nested Object</h1> <p id="p1"></p> <p id="p2"></p> <p id="p3"></p> <p id="p4"></p> <p id="p5"></p> <p id="p6"></p> <script> var p1 = new Object(); p1.firstName = "James"; p1.lastName = "Bond"; var p2 = new Object(); document.getElementById("p1").textContent = p2.firstName; document.getElementById("p2").textContent = p2.lastName; p3 = p1; // assigns object p3.firstName; // James p3.lastName; // Bond document.getElementById("p3").textContent = p3.firstName; document.getElementById("p4").textContent = p3.lastName; p3.firstName = "Sachin"; // assigns new value p3.lastName = "Tendulkar"; // assigns new value document.getElementById("p5").textContent = p3.firstName; document.getElementById("p6").textContent = p3.lastName; </script> </body> </html>
Result: