Javascript Functions

What is a function?
How to use javascript functions?


A function is nothing but a group or block of statements doing a specific task.
function name()
// set of statements that will be executed

A function has to be defined in the above syntax.
The name "function" followed by the name we choose for the function and then open and close brackets. The statements that will do the specific operation are then group together under this name using braces.
A function may or may not return a value. A function may or may not have parameters value.
Invoking a function:
The statements inside the function will not be executed automatically. We have to invoke or call the function to execute the statements. Just calling the name of the function will invoke the function. i.e. if we write a function with the name "test" calling it as "test();" will invoke the function.


<script language="javascript">
function test()
document.write(" ---- This is a test function ---- ");


Ask Questions

Ask Question