Table of Contents
hide
Definition
- Function is a named block of statements which can be executed/used as per need again and again in the program simply by writing its name and can return some value.
Features
- It is useful in making a program modular and understandable.
- Parameters : The arguments received by the function in a list of corresponding values are called parameters. These values can be assigned to local variables within the function.
- The return statement is used to return a value from a function. A variable using assignment operator can hold the returned value.
- Nested Function : When a function is called inside another function, as per need is known as Nested function.
To Define a function :
- Syntax :
function function_name(parameter_list)
{
- Example :
function msg()
{
document.write(“Hello India“);
}
To Call a function :
- A function can be called by simply writing the name of the function along with the name & list of arguments, if any present in the function.
- A function call can also be used in an event handler code also.
- Syntax :
function_name(parameter_list);
- Example :
msg();
0 Comments