Control Flow Flashcards
What is flow control?
When writing programs, you want your data to take the correct path. You want it to turn left or right, up, down, reverse, or proceed straight ahead when it’s supposed to.
We call this flow control.
What is a conditional?
A conditional is a fork (or multiple forks) in the road.
They use the keywords ‘if’ and ‘else’
What is a clause in this context?
A block, statement, or expression
What are operands?
The expressions or values that an operator uses are its operands. In comparisons, the expressions to the left and right of the operator are the operands. For instance, the equality comparison x === y uses the === operator with two operands: x and y.
What is this ‘===’ operator called?
The strict equality operator, also known as the identity operator, returns true when the operands have the same type and value, false otherwise.
What is this ‘!==’ operator called?
The strict inequality operator returns false when the operands have the same type and value, true otherwise. Note that !== is the inverse of ===: when === returns true, !== returns false, and vice versa.
What is this ‘==’ operator called?
The non-strict equality operator, also known as the loose equality operator, is similar to ===.
However, when the operands have different types, == attempts to coerce one of the operands to the other operand’s type before it compares them, and it may coerce both operands in some cases.
The result is true when the final values are the same, false otherwise. The coercion behavior can lead to unexpected results. For instance, when we compare the number 5 to the string ‘5’ using ==, we get true; with ===, we get false.
What is this ‘!=’ operator called?
The non-strict inequality operator, also known as the loose inequality operator, is similar to !==. However, when the operands have different types, != attempts to coerce one of the operands to the other operand’s type before it compares them, and it may coerce both operands in some cases. The result is false when the final values are the same, true otherwise.
What is this ‘<’ operator called?
The less than operator returns true when the value of the left operand has a value that is less than the value of the right operand, false otherwise.
What is happening here?
When comparing strings, the comparison is character-by-character. JavaScript moves from left-to-right in the strings looking for the first character that is different from its counterpart in the other string. Once it finds a character that differs, it compares that character with its counterpart, and makes a decision based on that. If both strings are equal up to the length of the shorter string as in the next to last example, then the shorter string is considered less than the longer string.
The final example shows that if you use < with two different types, some sort of coercion will take place. In this case, “42” gets coerced to a number, so a numeric comparison takes place. Don’t try to remember this.
What is this ‘>’ operator called?
The greater than operator returns true when the value of the left operand has a value that is greater than the value of the right operand, false otherwise.
What is this ‘<=’ operator called?
The less than or equal to operator returns true when the value of the left operand has a value that is less than or equal to the value of the right operand, false otherwise. Note that =< is not a valid comparison operator.
What is this ‘>=’ operator called?
The greater than or equal to operator returns true when the value of the left operand has a value that is greater than or equal to the value of the right operand, false otherwise. Note that => is not a valid comparison operator.
What is this ‘!’ operator called?
The not operator returns true when its operand is false and returns false when the operand is true. That is, it negates its operand. Note that, unlike most operators, ! takes a single operand; the operand appears to the right of the operator.
What is the ‘&&’ operator called?
The ‘and’ operator returns true when both operands are true and false when either operand is false.
What is the ‘||’ operator called?
The or operator returns true when either operand is true and false when both operands are false.