To create objects, the new operator is used to create an instance of an object. The new operator is followed by the constructor method.
The variable contains a reference to the new object. The properties assigned to the object are not variables and are not defined with the var keyword.
<html> <head> <title>User-defined objects</title> <script> var book = new Object(); // Create the object book.subject = "Perl"; // Assign properties to the object book.author = "Tutorialspoint"; </script> </head> <body> <script> document.write("Book name is : " + book.subject + "<br>"); document.write("Book author is : " + book.author + "<br>"); </script> </body> </html>
Book name is : Perl Book author is : Tutorialspoint