check it's type...(the fact I wrote this means it's not what you would guess)
js> var a = []+[]
undefined
js> typeof a
'string'
that's a little odd to me. ------------------
Back to my argument that a lot of this behavior is normal
js> []+{}
"[object Object]"
that is really misleading, remember when I said array plus something is merging strings?
> ['hi']+{}
'hi[object Object]'
what your example has actually done is printed the string notation for an object and put an empty string in front of it. That's totally normal/expected behavior. ------------------
With this next one, it is odd but it is still expected behavior
js> true+true===2
true
js> true-true===0
true
this isn't that surprising because you are forgetting something really important, boolean + boolean will be coerced into an int to fit your strict need for addition.
js> true+true
2
js> false+true
1
Therefore if you compare the results it will not only equal the number 2 but also be a number itself!
js>true+true === 1+1
true
I hope this helps everyone understand these oddities that aren't specific to just javascript.
check it's type...(the fact I wrote this means it's not what you would guess)
that's a little odd to me.------------------
Back to my argument that a lot of this behavior is normal js> []+{} "[object Object]"
that is really misleading, remember when I said array plus something is merging strings? > ['hi']+{} 'hi[object Object]'
what your example has actually done is printed the string notation for an object and put an empty string in front of it. That's totally normal/expected behavior.
------------------
With this next one, it is odd but it is still expected behavior
this isn't that surprising because you are forgetting something really important, boolean + boolean will be coerced into an int to fit your strict need for addition.
Therefore if you compare the results it will not only equal the number 2 but also be a number itself!
I hope this helps everyone understand these oddities that aren't specific to just javascript.