Member-only story
JavaScript Ellipses: The Spread and Rest Syntax
Helpful shorthands for modern JavaScript
Enter Javascript Ellipses (…)
Modern JavaScript allows us to use three dots, …
, also known as an ellipsis, to perform certain transformations and shorthand methods. The use of ellipses falls into two categories: rest syntax and spread syntax. I’ll explain each of these in turn.
Rest Syntax
Rest syntax allows a programmer to retrieve the remaining items — the rest of the items — in a collection that the programmer has not used, such as objects, arrays, or function arguments.
Let’s take a look at a few examples.
Rest syntax with object deconstruction
Modern JavaScript allows us to deconstruct objects. That is to say, we can define variables and assign values to them quickly from an existing object. Here’s a simple example:
In this example, we first define an object. Then, using object deconstruction, we pull…