function construct
The function construct creates a
custom function. This function can then
be called elsewhere in a code by passing
some parameters to it.
Syntax
function functionName(parameters) {
commands that a function executes.
};
Example
Let's create and call a function:
// We create a function:
function func() {
alert('!');
}
// We call a function:
func(); // shows '!'
Example
Let's create the function that takes two numbers as a parameter and displays their sum:
function func(num1, num2) {
alert(num1 + num2);
}
func(1, 2); // shows 3
See also
-
the lesson from JavaScript tutorial
detailing how to work with functions