0
Why does this code, the result is false ??
9 Respuestas
+ 2
Because an integer type doesn't equal a string/character type.
+ 2
Slick but in the code it's "==" not "===" which I am still confused about because "==" compares the value regardless of the data type tho while "===" compares the value and the data type. I'm confused as well on why 1 == '1' is false.
or does Ruby do not have the "===" operator.
UPDATE:- I was thinking of Javascript that is why. Sorry about that.
+ 2
MrDevEzeoke All i know is when i switched '1' to 1 the output is True. Logically, that's the answer.
Not sure about ruby equal signs, but they seem to follow the same rules as other languages. I could be wrong!
+ 2
Where's the logic in the second sentence? 1 is definatley 1. But that don't mean 1 == '1'.
Looking it up, all it says is that == is equal to, doesnt say anything about different data types. === is case equality and will check equality in whatever a "case" is. I still think it's the different data types
+ 2
Oh...
I see, because there is different data types...
Thanks for the answer MrDevEzeoke 🌟αnurαg kumαr🌟 Slick ...
+ 2
1 == '1' is false because 1 is int type and something which is written inside double or single quotes is called string .
https://code.sololearn.com/cQ8Ak6rLvF9N/?ref=app
+ 1
1 is 1
That mean's 1 == '1'
The question is
"Why does this code, the result is false..."
+ 1
Because any number which is not surrounded in quotes are numbers ex----->5 is a number and anything that is surrounded by quotes are characters ex------>'6' and "6" is a character
That's why your
Program:
puts 1=='1'---->give false ;
puts 1==1------->give true;
Because both are same data types
I think you have understood properly my friend Jeff's
: )
+ 1
Jeff's JK (HTML challenger and the coders 💻)🇮🇩 So overall, it's False because they are different data types.