What are the latest operators added to JavaScript?

JavascriptWeb DevelopmentFront End Technology

The latest operators added to JavaScript are spread operator and rest.

Rest operator

With rest parameter, you can represent number of arguments as an array. ES6 brought rest parameter to ease the work of developers. For arguments objects, rest parameters are indicated by three dots … and preceds a parameter.


Let’s see the following code snippet to define rest parameter

         function addition(…numbers) {
            var res = 0;
            numbers.forEach(function (number) {
               res += number;
            return res;

Spread Operator

It allow the expression expand to multiple arguments, elements, variables, etc. 


You can try to run the following code to learn how to work with spread operator

Live Demo

         var a, b, c, d, e, f, g;
         a = [10,20];
         b = "rank";
         c = [30, "points"];
         d = "run"

         // concat method.
         e = a.concat(b, c, d);

         // spread operator
         f = [...a, b, ...c, d];
Updated on 16-Jun-2020 08:10:14