Create a function in JavaScript
Description
The following code shows how to create a function.
Example
<!-- w w w .j a v a 2 s. c om-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function sum (num1, num2) {
return num1 + num2;
}
document.writeln(sum(1,2));
</script>
</head>
<body>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Definition
Call a function defined later in JavaScript
Call a function in hyperlink in JavaScript
Call function inside a function in JavaScri...
Call your function in JavaScript
Call your function in body onLoad event in ...
Convert function to string in JavaScript
Create a function with Function constructor...
Use Bind to create a new new function whose...
Use apply function to call a function in Ja...
Use function as variable in JavaScript
Use function.call() to call a function in J...
Use function caller property in JavaScript
Use function reference value passing in Jav...
Use function to calculate average in JavaSc...
Use same name for different functions in Ja...
Use this to reference function context in J...
Use typeof to check function variable in Ja...
Call a function defined later in JavaScript
Call a function in hyperlink in JavaScript
Call function inside a function in JavaScri...
Call your function in JavaScript
Call your function in body onLoad event in ...
Convert function to string in JavaScript
Create a function in JavaScript
Create a function variable in JavaScriptCreate a function with Function constructor...
Use Bind to create a new new function whose...
Use apply function to call a function in Ja...
Use function as variable in JavaScript
Use function.call() to call a function in J...
Use function caller property in JavaScript
Use function reference value passing in Jav...
Use function to calculate average in JavaSc...
Use same name for different functions in Ja...
Use this to reference function context in J...
Use typeof to check function variable in Ja...