You should use the
function keyword to create a new function. Also, you need to name this function and define arguments that the function should take:
The function definition structure:
- function name (should be in camelCase like variables);
- arguments are in parentheses (
- code block in curly brackets (
Functions have their own data usage space. Arguments are literals passed to a function. The function uses these arguments as variables. Arguments disappear when the function finishes executing. Functions have their own data usage space.
To define arguments, you need to give a name to each argument:
If a function accepts multiple arguments, they must be separated by commas (
Arguments are used like variables inside the function code block.
To use a function, you should call it by parentheses (
()) and give the arguments if a function expects it: