liveBook · Manning

Rest operator

In JavaScript, rest syntax uses three dots to collect remaining function arguments, array elements, or object properties into a single binding.

How 3 Manning books explain it

Essential TypeScript 5, Third Edition

A rest parameter collects an arbitrary number of function arguments into a single parameter value.

How it is used
Allows functions to accept extra arguments without declaring a separate parameter for each one.
How deep it goes
Explains syntax, last-position and single-parameter rules, array initialization, typed values, and calls with varying argument counts.
Examples
Works through price summation with mixed JavaScript values and a TypeScript tax calculation with zero or several extra fees.
What you can do after
Build it from scratch: define a TypeScript function that collects and totals a variable number of typed extra arguments.

Read how Essential TypeScript 5, Third Edition explains rest operator →

Secrets of the JavaScript Ninja, Second Edition

A function parameter syntax that collects remaining supplied arguments into a single array-like value.

How it is used
Collects excess function-call arguments under one named parameter so a function can process a variable number of values.
How deep it goes
Explains the syntax, array collection, and final-parameter restriction, and demonstrates sorting without detailing browser compatibility.
Examples
Demonstrates `multiMax(3, 1, 2, 3)`, sorting the remaining values, and multiplying the first by the largest.
What you can do after
Apply `...name` to collect remaining arguments into an array and process them inside a function.

Read how Secrets of the JavaScript Ninja, Second Edition explains rest operator →

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond

A function parameter in JavaScript syntax that collects the remaining arguments into a single array binding and must appear last in the parameter list.

How it is used
Collects variable numbers of function arguments for array processing or forwarding through a wrapper.
How deep it goes
Explains the syntax, array binding, last-position rule, and forwarding pattern through short worked examples.
Examples
Uses family and property-selection functions, an image-processing wrapper, and a CSS-class exercise.
What you can do after
Apply it via JavaScript rest parameters to collect extra arguments and pass them through a logging wrapper.

Read how Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond explains rest operator →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.