A function is a reusable block of code that is driven by an event or executed when it is invoked.
Alert: A dialog box pops up.
1. Define the function:
Function name () {
function body; (code block)
}
JS is very sensitive to case, so function must be lowercase. When a function is called, the function must also be called by the same name.
2. Function calls:
After the function has been defined, it cannot be executed automatically and needs to be called.
Call Mode:
1>, calling within the <script> tag
<script>
Function Demo () {
Alert ("Hello World");
}
Demo ();
</script>
2>, calling in an HTML file
Event invocation (such as onclick)//does not test whether the function name can be called directly in the file, and then the test can be called directly in the file
3. Operation of function parameters:
The declaration of an argument function in JS is particularly simple, and does not require declaring the type of the parameter because it is a weakly typed language.
such as: function demo (A, b) {
}
3.JS function