- 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 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.
Example
You can try to run the following code to learn how to work with JavaScript objects with object() constructor −
<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 type="text/javascript"> 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
- What is a constructor to create String object in JavaScript?
- How to create JavaScript objects using new operator?
- How to create a third object from two objects using the key values in JavaScript?
- How to create a Number object using JavaScript?
- How to create a URL object using JavaScript?
- How to create objects in JavaScript?
- How to transform object of objects to object of array of objects with JavaScript?
- What is the main difference between objects created using object literal and constructor function?
- How to check if the constructor of an object is a JavaScript Object?
- Duplicating Objects using a Constructor in Java
- Add a property to a JavaScript object constructor?
- Add a method to a JavaScript object constructor?
- How to define a JavaScript function using Function() Constructor?
- How to create dynamic values and objects in JavaScript?
- How to create object properties in JavaScript?

Advertisements