freecoding.school100% FREE · NO SIGNUP
Closure CavesISSUE #3 of 61

parameters · default · rest

LambdaVSThe Mutator
Lambda saysParameters can have defaults and a rest parameter that gathers extra arguments.

Give defaults inline: function greet(name = "guest"). A rest parameter (...args, always last) collects any extra arguments into an array. Destructure parameters for "named arguments": function f({x, y}). These make function signatures self-documenting and flexible.

Power-ups you unlock

The Mutator attacks — common mistakes

Boss battleWrite a function with a default parameter and a rest parameter.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>function tag(label='item', ...vals){ return label+': '+vals.join(','); }
document.getElementById('o').textContent=tag('nums',1,2,3)+'\n'+tag();</script></body></html>
▶ Open the interactive comic issue
‹ Arrow Functions · ShorthandReturn Values · Explicit Vs Implicit ›