Module 5 · Functions: Declarations, Arrows, Defaults and Rest
Every Form, One by One: Declarations, Arrows, Defaults and Rest
Free with an accountReading
Kenji writes a discount function for his shop's till. A customer with no coupon should get the house discount of 10 percent, so his first line is percent = percent || 10;. Every test passes. Then a sale arrives with a coupon of exactly 0 percent, a fixed price with nothing off. The till takes 10 percent off anyway. The section on default parameters shows why || did that, and how to say what Kenji meant.
Checking what this lesson needs for you…
What is inside Every Form, One by One: Declarations, Arrows, Defaults and Rest
- Function declarations
- Function expressions: a function stored in a name
- Arrow functions: the short form
- Parameters and arguments at the edges
- return at the edges
- Default parameters
- Rest parameters: any number of arguments
- The spread call: a list into separate arguments
- Functions as values
- The arguments object Intermediate