- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add properties and methods to an object in JavaScript?
To add properties and methods to an object in JavaScript, use the prototype property.
Example
You can try to run the following code to learn how to work with prototype −
<html> <head> <title>JavaScript prototype property</title> <script> function book(title, author) { this.title = title; this.author = author; } </script> </head> <body> <script> var myBook = new book("Amit", "Java"); book.prototype.price = null; myBook.price = 500; document.write("Book title is : " + myBook.title + "<br>"); document.write("Book author is : " + myBook.author + "<br>"); document.write("Book price is : " + myBook.price + "<br>"); </script> </body> </html>
- Related Articles
- How to add properties and methods to an existing object in JavaScript?
- How to add, access JavaScript object methods?
- How to add, access, delete, JavaScript object properties?
- How to create an object and access its properties in JavaScript?
- How to define methods for an Object in JavaScript?
- How to add properties from one object into another without overwriting in JavaScript?
- How to add an element to a javascript object?
- How to create object properties in JavaScript?
- How to delete object properties in JavaScript?
- How to duplicate Javascript object properties in another object?
- Extract properties from an object in JavaScript
- How to modify properties of a nested object in JavaScript?
- How to display methods and properties using reflection in C#?
- Remove number properties from an object JavaScript
- Shortest syntax to assign properties from function call to an existing object in JavaScript

Advertisements