what is a function?

Something which looks like a variable name, and adds parenthesis to it called as a function.
Function takes parameters, which are defined in the parenthesis. More than one parameters are separated with comma.
For Example : alert() is a function. It shows a pop-up box, we need to send a "string" as a parameter to tell the function what to show in the pop-up box.

We can create our own functions. For example we will create a function which adds two numbers:

function add(no1,no2){
        var result = no1 + no2;
         return result;
}

add(5,5);

The advantage of using return statement is, it tells the browser to use the result variable out of the function.

No comments:

Post a Comment

Overview of AngularJS

AngularJS is an open source web application framework. It is now maintained by Google . The most of the code can be eliminated by using th...