How to create JavaScript objects using object() constructor?

A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable.

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.


You can try to run the following code to learn how to work with JavaScript objects with object() constructor −

Live Demo

      <title>User-defined objects</title>
         var book = new Object(); // Create the object
         book.subject = "Perl"; // Assign properties to the object = "Tutorialspoint";
      <script type="text/javascript">
         document.write("Book name is : " + book.subject + "<br>");
         document.write("Book author is : " + + "<br>");


Book name is : Perl
Book author is : Tutorialspoint