I think the answer is no, most languages do not consider "undefined" to be false. Of course, it is important to know the features of the language in order to understand how it handles true , false , NULL (or nil ), etc.
You noted this with Ruby, so here are some examples of Ruby:
>> x
As for “why evaluate undefined as false”, this can be convenient when you need to know that a variable is defined before using it. For example, in Ruby, you often see this:
if x && x == "some interesting value" do_important_thing end
If x is undefined, the first part of the condition returns false and shorts the operator. Which is much cleaner than:
if x.nil? if x == "some interesting value" do_important_thing end end
zetetic
source share