+ 1
Type conversion: why is this true?
var a = (1==="1"?false:true); alert(a); //true I thought === meant âalike in both content and typeâ therefore, how can it be true that 1===â1â? Ah, wait... is it because the statement, even though 1 ===â1â is false, the Ternary statement has the term âtrueâ to be returned since it is in the final position in the statement?
3 RĂ©ponses
+ 1
Well, either at fault or very sneaky quiz question! ;-)
0
It's a normal result. Here it's used identity operator "===" checks not only value , but also type => number and string (different types) so Boolean check is false => the value of a is true (after ":", because the boolean check is false). You can find more info here: https://www.w3schools.com/js/js_comparisons.asp
Hope it helps you.
0
Indeed. That is the answer I came to after thinking about it :-)