In Ruby, why are the following lines true?
0 && 1 == 1 1 && 0 == 0
Why are they different and aren't both 0?
Boolean AND operator &&
returns its second operand if first is not false. 0
and 1
are true
in boolean expressions in Ruby. Only nil
and false
are false in boolean expressions.
nil && 15 # => nil 15 && 17 # => 17 15 && nil # => nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With