A JavaScript function is a block of code designed to perform a particular task.
A JavaScript function is executed when "something" invokes it (calls it).
The code inside the function will execute when "something" invokes (calls) the function:
- When an event occurs (when a user clicks a button)
- When it is invoked (called) from JavaScript code
- Automatically (self invoked)
When JavaScript reaches a return statement, the function will stop executing.
Using the example above, toCelsius refers to the function object, and toCelsius() refers to the function result.
Accessing a function without () will return the function object instead of the function result.
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
} document.getElementById("demo").innerHTML = toCelsius;
Variables declared within a JavaScript function, become LOCAL to the function.
Local variables can only be accessed from within the function.


