Saturday, 30 April 2016

JavaScript Function With Example

JavaScript Function


Definition :-

 In JavaScript is by using the function keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces {}.

Syntax:-
----------------------------------------------
function functionName(parameters){
    statements
}

Example:-
-----------------------------------
function myFunction(a, b) {
    return a * b;
}

How to use this function in Script.

<!DOCTYPE html>
<html>
<body>

<h1>a function returns the result : </h1>

<p id="demo"></p>

<script>
function myFunction(a, b) {
    return a * b;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
</script>

</body>
</html>

Result:- 

a function returns the result: 12


Factorial of a Number

Recently Viewed