filmov
tv
Functions in JS

Показать описание
# functions in JS
How to use functions in JS and NodeJS
### contents
1. JavaScript Functions
2. JavaScript Function Syntax
3. Function Invocation
4. Function Return
5. Why Functions?
6. The () Operator Invokes the Function
7. Functions Used as Variable Values
8. Local Variables
## JavaScript Functions
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).
## JavaScript Function Syntax
A JavaScript function is defined with the `function` keyword, followed by a **name**, followed by parentheses **()**.
## Function Invocation
The code inside the function will execute when "something" **invokes** (calls) the function
## Function Return
When JavaScript reaches a `return` statement, the function will stop executing.
If the function was invoked from a statement, JavaScript will "return" to execute the code after the invoking statement.
The program returns on the next line of code.
## Why Functions?
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
## The () Operator Invokes the Function
Using the example above, `toCelsius` refers to the function object, and `toCelsius()` refers to the function result.
## Functions Used as Variable Values
Functions can be used the same way as you use variables, in all types of formulas, assignments, and calculations.
## Local Variables
Variables declared within a JavaScript function, become **LOCAL** to the function.
Local variables can only be accessed from within the function.
How to use functions in JS and NodeJS
### contents
1. JavaScript Functions
2. JavaScript Function Syntax
3. Function Invocation
4. Function Return
5. Why Functions?
6. The () Operator Invokes the Function
7. Functions Used as Variable Values
8. Local Variables
## JavaScript Functions
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).
## JavaScript Function Syntax
A JavaScript function is defined with the `function` keyword, followed by a **name**, followed by parentheses **()**.
## Function Invocation
The code inside the function will execute when "something" **invokes** (calls) the function
## Function Return
When JavaScript reaches a `return` statement, the function will stop executing.
If the function was invoked from a statement, JavaScript will "return" to execute the code after the invoking statement.
The program returns on the next line of code.
## Why Functions?
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
## The () Operator Invokes the Function
Using the example above, `toCelsius` refers to the function object, and `toCelsius()` refers to the function result.
## Functions Used as Variable Values
Functions can be used the same way as you use variables, in all types of formulas, assignments, and calculations.
## Local Variables
Variables declared within a JavaScript function, become **LOCAL** to the function.
Local variables can only be accessed from within the function.