- 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 create objects in JavaScript?
To create objects, the new operator is used to create an instance of an object. The new operator is followed by the constructor method.
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.
Example
You can try to run the following code to learn how to create objects in JavaScript −
<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>
Output
Book name is : Perl Book author is : Tutorialspoint
- Related Articles
- How to create dynamic values and objects in JavaScript?
- How to create JavaScript objects using new operator?
- How to create JavaScript objects using object() constructor?
- How to create class objects in Python?
- How to create a third object from two objects using the key values in JavaScript?
- How to compare two objects in JavaScript?
- Create many JavaScript objects as the same type?
- How to create instance Objects using __init__ in Python?
- How to create wrapper objects in JShell in Java 9?
- How to count JavaScript array objects?
- How to merge two JavaScript objects?
- How to access nested json objects in JavaScript?
- How to shallow copy the objects in JavaScript?
- How to concatenate two JavaScript objects with plain JavaScript ?
- How to compare two JavaScript Date Objects?

Advertisements