Odd add behavior in jQuery

I was looking through some old questions related to a downstream post and I came across How to add 2 numbers in jQuery and I saw that:

$(1)+$(2)="[Object object][Object object]"

So then I tried to see what I pulled out $(1), and he turned out [1], as well as for $(2)and [2].

Usually, when you try to add [1]+[2], he will give you "12", but if you add $(1) and $(2), he will give you "[object Object][object Object]".

What is the explanation for this behavior?

+4
source share
1 answer

$ (1) may appear in your console as [1], but not fool, it is still a jQuery object, not an int in an array.

console.log(Array.isArray($(1)) //false

[object Object] , - , [ Object], .

, , , ( , ), .

+5

All Articles