Caffeinated Coder
Book an appointment
Lesson 04 · Typing JavaScript

Typing functions

A function is a small machine: values go in, one value comes out. Follow area(w, h) as its two parameters get types, the call area(3, 4) fills the slots and returns 12, and tsc catches a wrong return and a missing argument before anything runs. Then a default value, h = w, makes area(3) work and print 9.

10 min9 steps5 questionsBeginner
Fig 4 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.