Sign in
Log inSign up

Rest and Spread operators in ES6

Default profile photo
Anonymous
·Apr 10, 2018
const Mathlib = {

    multiply(...abc){

        return this.add(...abc)//  what argument it is passing to add function array or individual value 
    },

    add(p,q,r){
        return p+q+r;
    }
}

Mathlib.multiply(2,4,5);

above code is working fine ,so I am thinking if first time ....abc will store all value in array i.e when we are calling Mathlib.multiply(2,4,5) and second time when we are calling add(...abc) then also it should pass the array but it is passing individual value and thats why output is coming as 11.

So if above scenario is meaningful then below code should not produce error:


var a =[1,2,3];
...a  ;   // error

I am unable to understand what is going on under the hood??

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct