JavaScript Decision Making PDF
Equality
JavaScript decision making basically involves branching to different code outputs based on some form of logical comparisons that return Boolean Logic values of True or False. If this logic is true then branch to this code, if not then branch to different code. These logical comparisons and done using different Comparison Operators.
All letters, numbers, and characters are assign a Unicode number that you can use to compare with. If you are comparing A to a, you are not comparing two letters, instead you are comparing two unicode numbers.
For a complete Unicode List, Click Here
So if you are comparing A to a you are actually comparing 41(A) to 61(a). So if you compare is A > a, you are actually comparing is 41 > 61 which is False. So the comparison is A > a evaluates to False.
Basic Operators
- > : Greater Than
- < : Less Than
- >= : Greater Than or Equal To
- <= : Less Than or Equal To
Equality Operators
- == : Equal
- ∴ Checks for equality of value, not equality of type.
- ∴ This coerses both values to the same type and then compares them.
- ∴ This can possibly lead to some very unexpected results.
- ∴ 1 == "1" would evaluate to TRUE even though they are two different types, 1 is a number and "1" is a string.
- != : Not Equal
- ∴ Checks for equality of value, not equality of type.
- === : Strictly Equal
- ∴ Checks for equality of value, AND equality of type.
- ∴ 1 === 1 would evaluate to TRUE - They are both equal in value, and equal in type.
- ∴ 1 === "1" would evaluate to FALSE - They are equal value, but not equal in type.
- !== : Strictly non-Equal
- ∴ Checks for equality of value, AND equality of type.
The overall takeaway here is that for most instances, you should use === and !==.