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

4
  • 1
    developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Oct 29, 2019 at 3:27
  • You're looking at the spread operator. Commented Oct 29, 2019 at 3:27
  • @Shadow it's not an operator though, it's just a spread syntax. Commented Oct 29, 2019 at 3:27
  • Think of your second example as console.log.apply(console, Array.from(arguments)). See Function.prototype.apply() Commented Oct 29, 2019 at 3:32

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.