js-test-38

Can you add multiple arrays in JavaScript? What’s the output?

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

The function add(x, y, z) applies the + operator to the provided arguments. Or, simply put, adds them up.

In line 5 we provide it with 3 arrays.

Whenever you try to add arrays in JavaScript, they will be first converted to strings. Every element is separated from the next one by a comma and a single space. In our case:

  • 1, 2
  • 3, 4
  • 5, 6

Then these strings are concatenated, or “glued” together to make a result.


ANSWER: a string 1, 23, 45, 6 will be printed to the console.