A JavaScript function is a block of code designed to perform a particular task. and you can use the same code many times with different arguments, to produce different results.
Example function myFunction(p1, p2) { return p1 * p2; // The function returns the product of p1 and p2 }
Function Invocation
When an event occurs (when a user clicks a button) When it is invoked (called) from JavaScript code Automatically (self invoked)
Function Return When JavaScript reaches a return statement, the function will stop executing.
Functions Used as Variable Values Functions can be used the same way as you use variables, in all types of formulas, assignments, and calculations
Function declarations
A function definition (also called a function declaration, or function statement) consists of the function keyword, followed by:
The name of the function. A list of parameters to the function, enclosed in parentheses and separated by commas. The JavaScript statements that define the function, enclosed in curly brackets, {…}.
Function expressions