Prev Demo
Adding A Property To An Object In Javascript.
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Adding property to an object</h1> <p id="myId"></p> <script> function person(first, last, gender, height) { this.firstName = first; this.lastName = last; this.gender = gender; this.height = height; } var myFriend = new person("Charitha", "Goud", "Female", 5.3); var myColleague = new person("Surendra", "Goud", "Male", 5.8); myFriend.native = "Madanapalli"; document.getElementById("myId").innerHTML = "My friend is from " + myFriend.native; </script> </body> </html>
Note: We DO NOT save your trial code in our database.
Output