JavaScript functions are defined using the function keyword.
You can define a function either as a function declaration or as a function expression.
Earlier in this tutorial, you learned that functions are declared using the following syntax:
function functionName(parameters) { // code to be executed } |
Declared functions are not executed right away. Instead, they are “stored for future use” and are executed later when they are invoked (called).
function myFunction(a, b) { return a * b; } |
Semicolons are used to separate executable JavaScript statements. Since a function declaration is not an executable statement, it is not typical to end it with a semicolon. |