Objects
 
Functions also behaves like objects?
 
In Javascript functions also behave like objects. In JavaScript we can use function like an object. As an object is collection of variables and methods. The function also contains variables. We can access a function variables like object property by using dot(.) operator, as we access an object property.
 
Example
 

<html>

<head>

</head>

<body>

<script>

function road()

{

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= new Object

mycar.details=road

mycar.details()

</script>

</body>

<html>

 
Output is:

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

Click here to view result of this program in browser