Adding two empty arrays:
[] + []
results in an empty string. Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
+operator only exists for numbers and strings. When you use it on another type, JavaScript tries to convert the type (first to string, then int).When arrays are casts to strings, they are output as comma-separated strings.
So,
[] + []=>"" + ""=>"".Another example:
[1,2] + [3,4]=>"1,2" + "3,4"=>"1,23,4"Relevant Spec: https://tc39.es/ecma262/#sec-addition-operator-plus