Boolean objects in conditionals
david.hopwood at industrial-designers.co.uk
Fri Nov 28 16:15:53 PST 2008
Peter Michaux wrote:
> The following suggests (i.e. could be interpreted as) a false Boolean
> object is a "truthy" value.
>> (new Boolean(false)) ? "a" : "b"
> The following suggests a false Boolean object is a "falsy" value
>> ((new Boolean(false)) == true) ? "a" : "b"
> I understand what is going on here but it seems like a bad state of affairs.
I think the problem is that wrapper objects exist at all, not any specific
aspect of their semantics. There is no reason to have such wrappers in a
language in which is is possible for a given variable to hold either a
primitive value or an object reference. Programmers should simply avoid
using them (except where they are created and immediately discarded as a
result of calling a method on a primitive value).
More information about the Es-discuss