Logic and branching Logic is concerned with determining whether a statement is true or false. JavaScript uses logical statements to determine if a variable satisfies a certain condition and then makes decisions based on whether the statement is true or false. Boolean values A Boolean data type only has two possible values: true or false. This means that a logical statement will always return one of the two Boolean values. These values allow an algorithm to execute a particular branch of code to produce a desired outcome.
Logical operators Logical operators combine multiple boolean values into a single Boolean result. The most common logical operators are “And”, “Or”, and “Not”. The “And” operator (&&) demands that both Boolean values are true. The “Or” operator (||) demands that any of the Boolean values are true. The “Not” operator (!) swaps the Boolean value, so true becomes false and false becomes true. For example, “variable1 && !variable2” means, “Is variable1 true And variable2 false? If so return true.”
COMPARING VALUES Comparison operators are used in conditional statements. They compare different values to decide if a statement is true or false. COMPARISON OPERATORS Symbol
==
Meaning is equal value
===
is equal value and data type
!=
is not equal value
!==
is not equal value or data type
>
is greater than
>=
is greater than or equal to
< <=
is less than is less than or equal to
AND Burger AND fries. Both the statements must be true for the logical statement to return a true value.
OR Meal1 OR Meal2. One of the statements must be true for the logical statement to return a true value.