+ 6

Why false==="0" is false ?

Why false==="0" is false?

9th Aug 2017, 9:44 PM
Vincent Piat
10 Respuestas
+ 10
console.log (typeof false) console.log (typeof 0) console.log (typeof "0") #Output Boolean Integer String All may be worth zero, but === compares not only the value but also the type, so if you compare any of them, the result will be false because they are of different type
9th Aug 2017, 11:49 PM
The Gocho´s
The Gocho´s - avatar
+ 8
=== checks value and data type. 0 === 0 returns true 0 === "0" returns false
9th Aug 2017, 10:01 PM
Stamen
Stamen - avatar
+ 7
Paul, yes, that should be.
9th Aug 2017, 11:07 PM
J.G.
J.G. - avatar
+ 6
I'm not sure which language this is, but in most languages, False == 0, not False == "0". The difference is that in the correct way, 0 is an integer, but when it's in quotation marks, then it is a string. The same goes for True == 1 and not True == "1". Although, I'm not sure in my answer because you haven't provided enough info.
9th Aug 2017, 9:53 PM
Vukašin Zeljić
Vukašin Zeljić - avatar
+ 4
okay, so that is why! i mean i think that with == we have a conversion from string to int or even to bool directly and it returns true whereas === will eventually check if "0" is of type bool, right?
9th Aug 2017, 10:06 PM
Paul
+ 3
what language do you use?
9th Aug 2017, 9:49 PM
Paul
+ 3
i write the code in js: alert (false=="0") and the answer is true but for alert (false==="0") the answer become false do you understand why?
9th Aug 2017, 9:55 PM
Vincent Piat
+ 3
there is such thing as ===? what does it stands for? == is ok tho, but dunno why it accepts 0 as strung and return true
9th Aug 2017, 9:58 PM
Paul
+ 3
Thanks I understand now
10th Aug 2017, 7:06 AM
Vincent Piat
+ 2
javascript
9th Aug 2017, 9:50 PM
Vincent Piat