|
The use of functions makes the script shorter and more efficient,
and if any changes need to be made to the script, they only need
to be made once. Functions can also be placed into a separate .js
file, this allows multiple web pages to use the same scripts by
linking to the .js file. All functions are placed in the .js file,
meaning the scripts are even easier to update.
There is a certain syntax that a function must follow: -
- The script of the function must be placed in curly brackets {}
- The function name must be one word and must start with an alphabetical character or underscore.
- The function must not have the same name as a variable.
A function can be sent one or more pieces of information, these
pieces of information are called parameters. You can learn more
about parameters in the parameters
tutorial.
|