Today I learned...
- true or false values
- values can also be a result of comparisons, ex.
let isGreater = 5 > 2; \\true
- a special value that represents "nothing", "empty", or "value unknown"
- represents a value not assigned
- can explicitly assign
undefinedvalue to a variable but this is not recommended. Instead, use the
nullto assigning a "nothing" or an "empty" value.
- object type is special
- not a primitive value
- represents more complex data structures
- used to create unique identifiers for objects
- returns the type of argument
typeof xis equivalent to
typeof nullreturns object which is incorrect and an error of JS
typeof alertwill return function but functions are technically an object data type
- strings are compared letter by letter
- longer strings are greater
- uses Unicode
- converts values to numbers
undefinedis false (strict equality)
undefinedis true (loose equality)
null > 0is false, null becomes 0 with the comparison operator, 0 is not greater than 0.
null == 0is false, the == equality does not convert null and null does not equal 0.
null >= 0is true, null is converted to 0 and fulfills one of the operator condition (0 equals 0)
- shouldn't be compared to other values
undefined > 0is false
undefined < 0is false, examples 1 and 2 show undefined converted to NaN by the comparison operators and NaN is a numeric value and returns false for all comparisons.
undefined == 0is false, returns false because the undefined only equals
Treat comparisons with undefined\null with care.