Does OO JS have a mechanism for casting instance objects to boolean? I would like to be able to use custom instance objects directly in conditionals, and make assertions along the lines of !!(new Foo(0)) === false
, !!(new Foo(1)) === true
.
Python has
__nonzero__
and__len__
(see here)Ruby has
to_bool
.
How does JS do this for String literals ""
and zero 0
?