Unit3.3-JS-Functions

From WikiEducator
Jump to: navigation, search
Uou-logo-100px.png
Home  |  About UOU  |  About CEMCA  |  Contact Us    

Unit 3.3 Web application development tools & Technologies


3.3.5 JavaScript
  3.3.5.1 Data Types
  3.3.5.2 Variables
  3.3.5.3 Operators
  3.3.5.4 Conditional statement
  3.3.5.5 Dialog Boxes
  3.3.5.6 Functions


3.3.5.6 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>

                                                                                                 Next

Suggested Reading
  • Web Applications


 Suggested Videos
  • Video 01 Title
  • Video 02 Title
  • Video 03 Title