Functions are blocks of code that you save to be (re)used later; that specific fragment of code has a predefined purpose and it does a defined task. A function could receive some or no parameters to be able to execute and must always return something.
For example a function that calculates the area of a square would be something like this:
function calculateArea(length, edge) {
return length * edge;
}
If you want to use that function to calculate the area of a square with
length = 3
edge = 6
You need to do something like this:
let squareArea = calculateArea(3,6);
The value of squareArea will be set to 18.
Top comments (0)