0

It may be stupid but I really stuck with dot dot dot array(...[ ])

I was playing with arrays and I recently noticed a fact I don't understand.

Consider this function in Node.js environment:

function test(name, age, adress) {
    console.log(Array.from(arguments));
    console.log(...Array.from(arguments));
}

the output is:

// [ 'john', 25, 'new york' ]
// john 25 new york

I thought the second line was a concatenation(strng) of the array values ​​(arguments) until I execute this function in chrome's console:

screenshot

So my questions is:

  • does the second output is an array ?
  • If yes, what is the difference between these two arrays ?
  • What ...[array] actually does ?

Thanks in advance

Ameerudheen.K
  • 657
  • 1
  • 11
  • 31
Amadou Beye
  • 2,538
  • 3
  • 16
  • 37
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax – zerkms Oct 29 '19 at 03:27
  • You're looking at the spread operator. – Shadow Oct 29 '19 at 03:27
  • @Shadow it's not _an operator_ though, it's just a _spread syntax_. – zerkms Oct 29 '19 at 03:27
  • Think of your second example as `console.log.apply(console, Array.from(arguments))`. See [`Function.prototype.apply()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply) – Phil Oct 29 '19 at 03:32

0 Answers0