What does Three points in Javascript? known as the Spread or Rest Operator

About

The three points may refer to:

Usage example

Object Merge

You use it for object merge

obj1 = { color: "blue" };
obj2 = { color: "red", length: 10 };
obj3 = { name: "TheName" };
console.log('With Spread');
console.log({...obj1, ...obj2, ...obj3});
  • Result: Note that the values in conflict are overwritten and not added. The last object to the right has precedence.

Syntax

Spread

The spread syntax 1) allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.

Spread syntax can be applied only to iterable objects

  • For function calls:
myFunction(...iterableObj);
  • For array literals:
[...iterableObj, 4, 5, 6];

Rest

The rest parameter 2) syntax allows to represent an indefinite number of arguments as an array.

  • For function definition:
function f(a, b, ...theArgs) {
  // ...
}

where:

Documentation / Reference





Discover More
DOM - Child Nodes of a Node

Child Nodes of an element in the dom tree Via child selector, you can select element that are child of another element. The childNodes property of an element returns a collection of child Node....
DOM - NodeList (Collection)

A nodelist is the result of a selection that returns more than one node (Generally an element) Nodelist: HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection, interfaces are...
Javascript - Argument

This page is function arguments in javascript. It's also working with Rest argument
Javascript - Array

array in Javascript can contain any type of data. Different types of values can be stored within the same array Because arrays are special objects (as typeof implies), they can also have properties, including...
Javascript - Object

object in javascript An object is a data type in Javascript. An object follows a json data structure with key that holds property value. The value may be of a variable or a function In JavaScript, a...
Javascript - Set

The Set interface represents a set data type and works only with primitive type as there is no way to define an object equality function. object Jsdoc Declaration Add/Delete Size Contains...
React Props Chrome Plugin
React - Props

props is the only object argument passed from a component to another component. Props are similar to State, but is public and not fully controlled by the component. You can also pass arguments to...



Share this page:
Follow us:
Task Runner