Home
<!DOCTYPE html> <html> <body> <h1>Demo: Attach property to object</h1> <script> function Student() { this.name = 'John'; this.gender = 'M'; } var studObj1 = new Student(); studObj1.age = 15; alert(studObj1.age); var studObj2 = new Student(); alert(studObj2.age); </script> </body> </html>
Result: