Virtual Open Schooling Online courses available at Virtual Open Schooling (VOS), for more details kindly click here!
NIOS Silver Jubilee Year
NIOS

Functions

From NIOS
Jump to: navigation, search
Previous Page Home Page Next Page
ICT Applications

A function is a block of code that has a name. Whenever the nameis used the function is called which means that the code withinthe function gets executed. If a same set of statements to executenumber of times in different parts of the program it is better tocreate a function, write the statements inside it and call thefunction by name anywhere in program. By this way you canmake your program efficient and simple.The second purpose of JavaScript functions is to link actions ona web page such as mouse click, button presses, text selection,and other user actions can call JavaScript functions by includingsuitable tags inside HTML document.Function blocks begin with the keyword function, followed by thefunction name and parentheses (). The statements insidefunction block are written inside braces { }. The function may takesome values, known as parameters that are specified inside parentheses ( ) separated by comma one another and may also return some value.

function functionName(p1,p2...pn)
{
block of code goes here
}


The keyword function, should be in lower case. functionNamerepresents name of the function, p1,p2....pn are the parameters(optional), block of code goes inside braces { }. Usually functionsare written in the Head part of the HTML page, so that they willbe loaded first, when the page is loaded into browser.A function can be called inside the program, called by anotherfunction, or it can be called by a user action called event suchas mouse click, button presses etc.An example 8.8 showing defining and calling a function


Previous Page Home Page Next Page
ICT Applications