There are three ways to create objects in JavaScript, namely using the new Object method, using the literal character {}, and using the constructor.
#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.
We can use the new Object method to create an object using the root object Object.
After creation, you can use dot notation to add properties to the object.
The second method of creating an object can be created using literal characters. You can directly use the {} symbol to create an object. The properties in the object can also be created directly.
#The third way to create an object is to use the constructor to create it, using the function keyword and the object name to create it.
Then we use the console.log method to output and display the three objects created.
In the browser console page, you can see the three object variables created.
Related video tutorial sharing: js video tutorial
The above is the detailed content of What are the methods of creating objects in javascript. For more information, please follow other related articles on the PHP Chinese website!