Methods In JavaScript

Methods are set of actions that allow the access to the variables of an object. A Method contains the code to perform some task for an/many object(s). The methods and the variables forms an object.
 
Example
 
<html>

<head><title> Functions are like Objects </title>

</head>

<body>

<script>

function car()

{

var car = new Object

car.name=”Lancer”

car.color=”Blue”

car.no=”MAH2059″

document.write(“<br> Car Name :”+car.name)

document.write(“<br> Car Color :”+car.color)

document.write(“<br> Car Number :”+car.no)

}

var mycar= car

mycar()

</script>

</body>

</html>

 
Output is:
Car Name :Lancer
Car Color :Blue
Car Number :MAH2059

 

Scroll to Top