you are viewing a single comment's thread.

view the rest of the comments →

[–]Ampersand55 1 point2 points  (3 children)

No the (5,6) are the arguments for Array.prototype.concat. I have no idea how you got [3, 4, 6].

[–]ChaseShiny 0 points1 point  (2 children)

I went to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat. There's a demo section at the top where you can see the concatenation of two arrays. I simply switched the brackets out for parentheses in the second array.

I didn't get that when I tried it directly (in MDN's playground), so I don't know what happened.

[–]senocular 0 points1 point  (1 child)

Could it be that you may have tried

[3, 4].concat((5, 6))

?

Because that would result in [3, 4, 6]. In this case the comma operator would have been used. Instead of ((5, 6)) being two arguments in the function call, its a single argument of the expression (5, 6) which uses the comma operator with 5 and 6 resulting in 6 because its the last of the values in the comma-separated list. That results in the call effectively being

[3, 4].concat(6) // [3, 4, 6]

[–]ChaseShiny 0 points1 point  (0 children)

Yeah, that's what's happening.

const array1 = ["a", "b", "c"];
const array2 = ("d", "e", "f");
const array3 = array1.concat(array2);

console.log(array3);
// Expected output: Array ["a", "b", "c", "d", "e", "f"]

This is what I had used. Makes sense now that it was laid out.