Comparisons Flashcards
a==b
write not equal to
a != b
let result = 5 > 4 // returns
true
alert( ‘Z’ > ‘A’ ); // returns
alert( ‘Bee’ > ‘Be’ ); // returns
true
true
alert( ‘Z’ > ‘Z’ ); // returns
false
alert( ‘Glow’ > ‘Glee’ ); // returns and why
true
o is greater than e.
A capital letter “A” is not equal to the lowercase “a”. Which one is greater and why?
The lowercase “a”. Why? Because the lowercase character has a greater index in the internal encoding table JavaScript uses (Unicode).
alert( ‘2’ > 1 ); // returns and why?
true, string ‘2’ becomes a number 2
JavaScript converts the values to numbers.
alert( ‘01’ == 1 ); // returns and why?
true, string ‘01’ becomes a number 1
JavaScript converts the values to numbers.
let a = 0;
let b = “0”;
alert(a == b); // returns and why
true
An equality check converts values using the numeric conversion (hence “0” becomes 0), while the explicit Boolean conversion uses another set of rules.
alert( 0 == false ); // returns
true
alert( 0 === false ); // returns and why
false
Because the types are different
alert( 0 !== false );
true
alert( null === undefined );
false
alert( null == undefined );
true
For maths and other comparisons < > <= >=
null is converted to ________
number