0

Are there any (other) programming languages where string 'false' is not a truthy value?

php yes:
echo "<?= ('false'==true) ? 'yes':'no' ?>" | php
yes

python kind of:
>>> print(('false'==True))
False
>>> print(bool('false'))
True
>>>

javascript: no
console.log('false'==true)
false


bash: no
[[ 'false' == true ]] && echo "yes"
[[ 'false' != true ]] && echo no
no

ruby: no
ruby -e "print 'false' == true" 
false

This is a pretty general question but it's not as easy as you might think to find an answer in one place

111
  • 1,788
  • 1
  • 23
  • 38
  • 1
    Probably all strongly typed languages. e.g. `"false"` is a String in Java, not a valid boolean literal. Similar for Pascal. In C this wouldn't work either but mainly because there are no real boolean values in C (zero is considered "false", non-zero is considered true). –  Jan 10 '19 at 07:08
  • 1
    @a_horse_with_no_name to my horror I also just discovered that in php '0' == false – 111 Jan 10 '19 at 07:25

0 Answers0