Why is [1,2] + [3,4] = “1,23,4” in JavaScript?

前端 未结 13 1497
小蘑菇
小蘑菇 2020-11-22 16:56

I wanted to add the elements of an array into another, so I tried this:

[1,2] + [3,4]

It responded with:

\"1,23,4\"
         


        
13条回答
  •  清酒与你
    2020-11-22 17:38

    would be nice if you could overload operators in JavaScript but you can't: Can I define custom operator overloads in Javascript? you can only hack the "==" operator which converts to strings before comparing: http://blogger.xs4all.nl/peterned/archive/2009/04/01/462517.aspx

提交回复
热议问题