Loading, please wait...

Create an Object

Creating Objects

While creating a new object of the same type, we use the new keyword.

 

Syntax

var objectName = new Object ();

 

Code:

<html>
<body>
<h2>JavaScript Objects</h2>
<script>
var person = new Object();
person.name = "Nitin";
person.age = 22;
person.salary = 20000;
document.write(person.name + " is "+ person.age + " yrs old.");
</script>
</body>
</html>

In the above example, the new keyword is used to create an object.

Further, with the help of this object, we can assign the values to its methods and properties using dot notation.

 

Output: