Functions

Tools to use


Functions
A function is a reusable block of code that groups together a sequence of statements to perform a specific task.

Function Declaration
One way to create a function is by using a function declaration.

Calling a Function
The code inside a function body runs, or executes, only when the function is called.
To call a function in your code, you type the function name followed by parentheses.

Parameters
- Some functions can take inputs and use the inputs to perform a task.
- When declaring a function, we can specify its parameters. Parameters allow functions to accept input(s) and perform a task using the input(s).
- We use parameters as placeholders for information that will be passed to the function when it is called.
function calculateArea(length, width){
console.log(length * width);
}Arguments
When calling a function that has parameters, we specify the values in the parentheses that follow the function name.
The values that are passed to the function when it is called are called arguments. Arguments can be passed to the function as values or variables.

Practise On FreeCodeCamp
Go to freecodecamp and work on the code challenges on functions to understand how to use them well.
💡💡
** The End **

Functions and Loops in JS
By Roland Sankara
Functions and Loops in JS
- 3