Methods of an Object in JavaScript

“A method is a set of one or more statements that are executed by referring the name of the method.”


“A method can be defined as an action performed by an object.”

In real world, If we take bike as an object, which performs actions, such as blowing horn or accelerating speed. A complex application is divided into methods; as a result, code becomes more flexible and easy to maintain and debug.

Two simple steps are here for defining an Object:


Let's assume triangle is an object. Create a function : computearea(),

Follow the given Syntax and Code:

// method function
function computearea()
var area=this.base*this.altitude*0.5
return area()

In the above code the computearea() function calculates the area of a triangle. Now, associate the function computearea() to the object triangle,

See given code:

<SCRIPT type="text/JavaScript>
function triangle(b,a)

Now as usual we will call the method :

var mytriagle=new triangle (20,10)

So this was the Syntax of Methods of an JavaScript.

JavaScript supports seven built-in objects, which are


These objects are also called core language objects.

All above built-in objects have different objects. We will discuss in Next Post.