Comparisons
importance: 5
What will be the result for these expressions?
5 > 4
"apple" > "pineapple"
"2" > "12"
undefined == null
undefined === null
null == "\n0\n"
null === +"\n0\n"
5 > 4 → true
"apple" > "pineapple" → false
"2" > "12" → true
undefined == null → true
undefined === null → false
null == "\n0\n" → false
null === +"\n0\n" → false
Some of the reasons:
- Obviously, true.
- Dictionary comparison, hence false.
"a"is smaller than"p". - Again, dictionary comparison, first char
"2"is greater than the first char"1". - Values
nullandundefinedequal each other only. - Strict equality is strict. Different types from both sides lead to false.
- Similar to
(4),nullonly equalsundefined. - Strict equality of different types.