Spread Syntax vs Rest Parameter in ES2015 / ES6

前端 未结 10 1786
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 10:52

I am confused about the spread syntax and rest parameter in ES2015. Can anybody explain the difference between them with proper examples?

10条回答
  •  死守一世寂寞
    2020-11-27 11:08

    In reference to this i cant understand how we are passing a function and returning arguments in javascript

    Function is a set of instructions that takes some input and processes them and returns result.

    here we have an array [1, 2, 3, 4, 5, 6], and filter function iterates over each element and passes each element to positive functions which returns the number if it is even, else skips it.

    trace:

    1 => Filter(1) => positive(1) => skips 1,
    2 => Filter(2) => positive(2) => returns 2,
    3 => Filter(3) => positive(3) => skips 3,
    ...
    6 => Filter(6) => positive(6) => returns 6
    

    hence the result [2, 4, 6]

提交回复
热议问题