SoFunction
Updated on 2025-04-06

Detailed explanation of the use of prototype prototype attributes in JavaScript

The prototype property can add properties and methods to any object (Number, Boolean, String, Date, etc.).

Note: Prototype is a global property that can be used in almost all objects.
grammar

 = value

Example:

Here is an example showing how to add properties to an object using the properties of a prototype attribute:

<html>
<head>
<title>User-defined objects</title>

<script type="text/javascript">

function book(title, author){
   = title; 
   = author;
}
</script>
</head>
<body>
<script type="text/javascript">
  var myBook = new book("Perl", "Mohtashim");
   = null;
   = 100;
  ("Book title is : " +  + "<br>");
  ("Book author is : " +  + "<br>");
  ("Book price is : " +  + "<br>");
</script>
</body>
</html>

This will produce the following results:

Book title is : Perl
Book author is : Mohtashim
Book price is : 100