Boolean Logic: True & False
Boolean is one of the five primitives. There are only two possible options for Boolean value: True or False.
Boolean logic is simple writing statements that evaluate to be true or false. Then, we can combine those initial statements to create more complex statement that also evaluate to true or false.
Comparison Operators
Screenshot from Udemy Course Lecture |
Those two operators are all equal sign, but they are different. According to the course, "==" performs type coercion which means that it takes two numbers (or strings or variables) and tries to turn them into a similar type so that we can compare them.
In the meanwhile, "===" does not perform type coercion.
For example:
var x = 5;
x == "5" //true ("5" is a string. The "==" turns the string "5" to a number 5, so they can be equal. The result will be true)
x==="5" //false (The "===" can't turn string "5" to a number 5. Since these two "5" are different types, so the result is false)
Logical Operators
screenshot from Udemy course lecture |
For "||", one side is true, the whole thing is true. x===5 is true, so the result is true.
For "!", x===y is false, but the !(x===y) interprets x is not equal to y, so the result is true.
Truthy and Falsy Values:
According to the lecture, values that are not actually true or false, are still inherently "truthy" or "falsy" when evaluated in a Boolean context.
Falsy Values are: false, 0, '''', null, undefined, and NaN. Everything else is truthy.
When I type a "!" (Not) operator in front of each falsy values, the results are all true. Therefore, those values are fasly values.
Comments
Post a Comment