+ 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 Antworten
+ 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 :-)