PGDEL/DECP03/Unit3/21

From WikiEducator
< PGDEL‎ | DECP03‎ | Unit3
Jump to: navigation, search



Unit 3.3 Web application development tools & Technologies
Functions

Functions are the JavaScript statements to perform a specific task and can return a value. JavaScript function may take zero or more parameters.

Function
Syntax
Example
Pre-defined functions

JavaScript provides several built-in functions.

e.g. functions to perform explicit type conversion like eval(). parseInt(), parseFloat() etc.

var variable_name = function_name(parameter/s list);

eval() function is used to evaluate a string parameter(mathematical expression) to a numeric value.

val total = eval (“10+5+20”);

User-defined functions

User-defined functions are the JavaScript statements coded into a single unit to perform a specific task that can be used in many places whenever required.

function function_name(parameter 1, parameter 2, . . .){
// JavaScript statements
}


<HTML>
<HEAD>
<TITLE> Demonstating UDF </TITLE>
<SCRIPT type="text/javascript" >
function udf() {
   alert("Hello there");
}
</SCRIPT>
</HEAD>
<BODY onLoad="udf();">
Demonstrating User Define Function.
</BODY>
</HTML>

Road Works.svg Work in progress, expect frequent changes. Help and feedback is welcome. See discussion page. Road Works.svg