Loading, please wait...

Methods and Properties

Object Properties

Object Properties are separated by commas. The property name is followed by colon (:) and then a value.

We can access the object properties in this way:

 

Syntax

objectName.propertyName    
or     
objectName[‘propertyName’]

 

 

Object Methods

In JavaScript, Method is defined as a function which is responsible for displaying data of the functions on a screen.

 

Syntax

objectName.methodName()

 

Code:

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

 

 

Output:

 

 

 

 

 

 

 

 

 

 

 

Output: