In JavaScript, all objects are truthy [1], even new Boolean(false), empty arrays and empty objects:
> Boolean(new Boolean(false)) true > Boolean([]) true > Boolean({}) trueThat is different from how objects are converted to number and string, where you can control the result by implementing the methods valueOf() and toString() [2].
As an example, let’s assume that new Boolean(false) coerces to false and use it in an expression:
new Boolean(false) && 1 && trueThat expression is evaluated in two steps:
new Boolean(false) && 1 → new Boolean(false) new Boolean(false) && true → new Boolean(false)For each step, you need to coerce new Boolean(false) to boolean in order to determine the result.
> {}.toString.call(document.all) // an object '[object HTMLAllCollection]' > Boolean(document.all) // falsy! false > typeof document.all // strange! 'undefined'