Part #3: Functions — the block of code you can call with different input
It would be useful to write a block of code that will take input, perform computation, and returns output.
Defining the function simply names the function and specifies what to do when the function is called.
A function definition (also called a function declaration, or function statement) consists of the
function keyword, followed by:
- The name of the function.
An input to function with parameters
A list of parameters can be provided to the function, enclosed in parentheses and separated by commas.
A function can specify default input parameters
It will allow us to call a function with missing arguments.
A function can be assigned to a variable
Alternative more modern syntax using an arrow functions
Arrow functions are alternatively called lambda expressions.
What is confusing for beginners about arrow functions?
Arrow function can optionally use shorter syntax. Short syntax can be confusing for beginners.
As a beginner use parentheses
(), curly bracket