I understand that an empty string is falsy in javascript and a not-empty string is truthy in javascript.
However, why is 'false'
truthy in javascript, is there anything explicit in the specification? Is it a performance issue or are there situations where you would want the string 'false'
to represent true
?
false
is a command that always returns a non-zero error code, the double-bracketsif
construct still evaluates the stringfalse
as "truthy":if [[ false ]]; then echo ha; fi
. Only Perl, which attempts to treat strings as numbers whenever such a conversion might make sense, actually cares what the contents of a string are when determining its "truthiness", and even there"false"
is not considered false ("0"
and"undef"
are, though). – Ciracirca