+ 1
Why it's true?
I assign zero to variable and used this variable in 'if' statement. Why 'if' gives true? https://code.sololearn.com/cI7gd9xYPrwm/?ref=app
2 Respostas
+ 19
In Ruby, only 'false' and 'nil' are evaluated as false. 0 is evaluated as true and that's why the output of your code is 1.
+ 4
x = false
puts x ? 1 : 0
try this way
only true and false are boolean. 0 is not a boolean