Before reading this code you should have an understanding of Javascript function.
Steps of the code:
First of all, declare and initialize the variable length and width, which is the sides of the triangle. The value of length is 4 and width is 2.
In line number 3 we will call the function area(). On calling the function interpreter will jump to line 6.
In line 6 we have declared the function area(). It accepts two arguments which will be used as sides of the rectangle. The arguments are l and b.
In lines 8 and 9 we will calculate the area of a rectangle and return the calculated value to variable a in line 3.
The flow of code is
LINE 1
2
3 and then jump to line 6
7
8
9 then jump back to 3
4
var length = 4;
var width = 2;
var a = area(length,width)
console.log("The area of rectangle is "+a);
function area(l,b)
{
var ar = l*b;
return ar;
}
The output of the code is
The area of rectangle is 8