- The keyword function
- A function name
- A list of parameters.
- A block of statements to execute.
In other programming languages such as C/C++, you must explicitly declare you function type, its actual and formal parameters, and then write a separate definition for the function.
- function with parameters, but no return value
- function with parameter and a return value
- function without parameter and no return
- function without parameter and a return value
- class methods
- anonymous functions
We will discuss about each one of them in great detail in future lesssons.
- call function in the main program
- call function within another function
- call function from an HTML element such button, etc.
Whichever way you choose, once the function is called it will execute the statements within it.
It means that the variables that are defined inside the function can only be accessed by the function, not outside of it.
Parent Scope or Nested Scope
If a function is defined inside of another function, the parent function cannot access the variables of the child function. However, the child function can access variables within its own body and from the parent function.