Computer Science: Function - XLJasonHuo/Starfield GitHub Wiki

Functions are one of the most important parts of coding. A function in JavaScript is a group of code statements that are set to perform a task or calculations. However, in order to qualify as a function, it should have input and also output, you must define where the function should input and output inside the code.

Function Declaration

1: Name of the function

2: Bracket ()

3: Enclose all the calculations/tasks in a curly bracket {}

Return

When JavaScript notices a "return" statement, the function will stop executing, and return the value back to the caller.

Why Use Functions?

Functions can be reuse, define the function once, you can use it as many times as the coder wants.

Coders can use the same code many times for different arguments, in order to produce different results, without typing the same code every time the coder wants to use the same set of calculations/tasks.

↓↓ Demonstration of a function ↓↓

Function Demonstration