## Javascript #### Conditional Statements -
Boolean values
-
Making decisions in your code - conditionals
-
Comparison operators
---
Boolean values
true
or
false
(there is no maybe)
Truthy
A truthy value is a value that is considered
true
when converted to a Boolean value.
Falsy
A falsy (sometimes written falsey) value is a value that is considered
false
when converted to a Boolean value.
---
Equality (`==`)
The equality operator checks whether its two operands are equal. Unlike the strict equality operator,
it attempts to convert and compare operands that are of different types
.
Strict Equality (`===`)
The strict equality operator checks whether its two operands are equal. Unlike the equality operator, the strict equality operator
always considers operands of different types to be different
.
---
Inequality (`!=`)
The inequality operator checks whether its two operands are not equal. Unlike the strict inequality operator, it attempts to convert and compare operands that are of different types.
Strict Inequality (`!==`)
The strict inequality operator checks whether its two operands are not equal. Unlike the inequality operator, the strict inequality operator always considers operands of different types to be different.
--- ### Key Takeaways - Use `===` when testing for equality (it's safer). Use `==` once you understand truthiness (or you just can't get the job done with `===`). - Any value can be converted to a Boolean value: ```js myBool = Boolean(myVar); // Method 1 myBool = !!myVar; // Method 2 ``` --- ## `if` blocks An `if` block only runs if its expression evaluates to `true` ```js if (condition) { code to run if condition is true } run some other code ``` --- ## `else` blocks An `else` block only runs if all previous `if` and `else if` blocks have evaluated to `false`. ```js if (condition) { code to run if condition is true } else { run some other code instead } ``` --- ## `else` blocks An `else if` block only runs if its expression evaluates to `true` AND all `if` and `else if` blocks before it have evaluated to `false`. ```js if (condition) { code to run if condition is true } else if(condition) { code to run if condition is true AND the previous blocks evaluate to false } else { run some other code instead } ```