Javascript7

Function


«<Javascript6|Javascript8»>

User defined simple functions

Function is a set of statements recognized by a name and can be used as and when required (it is reusable). In JavaScript functions can be created inside the JavaScript tag only. “function” is a reserve word after which we type the name of the function to be created and then brackets. The code from where the function starts and where ends is kept in side curly braces.
Syntax:

function functionname(){
lines to be kept under this name
}

[Top]

Parameterized functions

Function is a set of statements recognized by a name and can be used as and when required (it is reusable).

A function can accept parameters and can used those accepted values for his purpose. A function can accept many parameters to which we can manage or use as per requirement in the code of that function.

Syntax:

function functionname(var1, var2,..){

lines to be kept under this name
}

[Top]

Functions Returning Values

Function is a set of statements recognized by a name and can be used as and when required (it is reusable).

A function can accept parameters and can return a value back to the calling position. The parameters accepted by a function can be used in the code of that function.

Syntax:

function functionname(var1, var2,..){

lines to be kept under this name return(variablename)

}

[Top]

Recursive Functions

A function which calls itself, is called a recursive function. When A function calls itself it gets repeated again and again until the desired condition meets. Recursive functions are such type of functions which calls themselves. A provision to escape from indefinite loop is made in the program.

[Top]

Scope of a variable

Any variable in a function is local to that function & the variables declared outside the function are called a global variables , the local variables can be accessed within the function only, while global variables can be accessed anywhere in the program.
[Top]

Example

[Top]
«<Javascript6|Javascript8»>

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.