Learn JavaScript

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

Module 5 · Functions: Declarations, Arrows, Defaults and Rest

When to Use Which: Declaration or Arrow, a Default or a Check, Recursion or a Loop

Free with an accountReading

Zara reviews Bob's pull request, the change he asks the team to merge. Half his functions are declarations, the other half are arrows, and nothing seems to decide which. "Does it matter?" she writes. Bob says it is only style. He is right about most of it, and wrong in exactly two places. This lesson finds both, then makes the other choices a function asks you to make.

Checking what this lesson needs for you…

What is inside When to Use Which: Declaration or Arrow, a Default or a Check, Recursion or a Loop

  1. One rule for the spelling
  2. The first place it matters: calling above the line
  3. The three spellings on one chart
  4. Choosing with a flowchart
  5. A default, ?? or a check
  6. Rest parameters or one array
  7. When code should become a function
  8. Recursion or a loop