Thanks for video! I've also looked at other explanations on internet and I found out that: - "" to number is 0; - [] to number is 0, because it first converts to string which is "", then it converts "" to number which is 0; - "" == 0 its true. So equals operator converts both to number, which means that "" to number is 0.
I've updated my code Gist to reflect the two Array differences for +[1] and +[1,2]. The Arrays get turned into the Primitive string values "1" and "1,2" before being converted to Numbers which is why we get the 1 and NaN results. Not sure why I had 0 written for the Objects. They will always be NaN. Thanks for pointing it out.
Nope. Everything that is not falsy is truthy in JS. The falsy values are: false, 0, "", null, undefined, and NaN. Arrays are Objects. They are not on the list, so they are truthy. Run this: if( [ ] ){ console.log('array is truthy'); } However, think about this - Convert an empty Array to a String and you get "". Convert that into a Boolean and you get false.