Conditionals Flashcards

Logical operators, if/else, switch statements

1
Q

What is control flow?

A

The order in which statements are executed in a program.

Control structures such as conditionals (if statements and the like) alter control flow by only executing blocks of code if certain conditions are met.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

OR || operator

A

Checks two values and returns a boolean.
*if one or both values are truthy = true
*if both values are falsy = false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

AND && operator

A

Checks two values and returns a boolean
*if both values are truthy = true
*if one or both values are falsy = false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Ternary Operator

A

Allows for a compact syntax in the case of binary
It accepts a condition followed by ?, then two expressions separated by :

If the condition is truthy, the first expression is executed
If the condition is falsy, the second expression is executed

let price = 10.5;
let day = “Monday”;

day === “Monday” ? price -= 1.5 : price += 1.5;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

if statement

A

Accepts an expression with a set of parentheses
*if the expression is truthy, the code executes
* if the expression is falsy, the code will not execute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

else statement

A

Can be added to an if block or statement, and will be evaluated only if the if condition is falsy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

switch statement

A

Checks an expression against multiple case clauses. If a case matches, the code inside that clause is executed.

The case clause should finish with a break keyword. If no case matches but a default clause is included, the code inside the default will be executed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Not ! operator

A

Can be used to invert a boolean value or invert the truthiness of non-boolean values

let lateToWork = true;
let oppositeValue = !lateToWork; //false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Comparison Operators

A

=== strict equal
!== strict not equal
> greater than
>= greater than or equal
< less than
<= less than or equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Truthy and Falsy Values

A

Values that are evaluated to true are known as truthy
Values that are evaluated to false are known as falsy

Falsy values include:
false
0
empty strings
null
undefined
NaN.

All other values are truthy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly