Learn JavaScript

Lesson 2 of 9 · Functions: Declarations, Arrows, Defaults and Rest

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

  1. Function declarations
  2. Function expressions: a function stored in a name
  3. Arrow functions: the short form
  4. Parameters and arguments at the edges
  5. return at the edges
  6. Default parameters
  7. Rest parameters: any number of arguments
  8. The spread call: a list into separate arguments
  9. Functions as values
  10. The arguments object Intermediate