The plus sign is either arithmetic or string concatenation. Empty arrays are converted to empty strings in the case of [] + [] .
The Array toString method returns a single line, which is a list of all elements of the array, separated by a comma.
In the above MDN link:
JavaScript calls the toString method automatically when the array should be represented as a text value or when the array refers to string concatenation.
The same idea of automatic type conversion is why true + true === 2 , and type conversion is the basis of many complex JavaScript tests such as this one .
source share