Function Syntax
function functionName(parameter1, parameter2) {
//code
}
where
function
is a keywordfunctionName
is the name of the function, by which it is calledparameter1
,parameter2
,.. are the parameters. arguments received by the function are received in parameters. Any number of parameters can be defined.code
is any valid JavaScript code.
Example
1. In the following program, we write a function add()
that takes three arguments, and returns their sum.
function add(a, b, c) {
result = a + b + b;
return result;
}
console.log(add(5, 4, 7));