JavaScript Conditionals Flashcards

1
Q

What is Control Flow?

A

Control flow is the order in which statements are executed in a program. The default control flow is for statements to be read and executed in order from left-to-right, top-to-bottom in a program file.

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

What are Control Structures?

A

Control structures such as conditionals (“if” statements and the like) alter control flow by only executing blocks of code if certain conditions are met. These structures essentially allow a program to make decisions about which code is executed as the program runs.

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

What is the Logical Operator “ll”?

A

The logical OR operator “ll” checks two values and returns a boolean. If ONE or BOTH values are truthy, it returns “true”. If BOTH values are falsy, it returns “false”. Example: 10 > 5 ll 10 > 20 // true. Example: 10 > 100 ll 10 > 20 // false

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

What is a Ternary Operator?

A

The ternary operator allows for a compact syntax in the case of binary (choosing between two choices) decisions. It accepts a condition followed by a “?” operator, and then two expressions separated by a “:”. If the condition evaluates to truthy, the first expression is executed. Otherwise, the second expression is executed. Example: 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

What is an “else” statement?

A

An “else” block can be added to an “if” block or series of “if”-“else-if” blocks. The “else” block will be executed ONLY if the “if” condition fails.
Example:
const isTaskCompleted = false;

if (isTaskCompleted) {
console.log(‘Task completed’);
} else {
console.log(‘Task incomplete’);
}

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

What is the Logical Operator “&&”?

A

The logical AND operator “&&” checks two values and returns a boolean. If BOTH values are truthy, then it returns “true”. If one, or both, of the values is falsy, then it returns “false”.
Example:
1 > 2 && 2 > 1; // false
4 === 4 && 3 > 1; // true

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

What is an “if” statement?

A

An “if” statement accepts an expression with a set of parentheses: If the expression evaluates to a truthy value, then the code within its code body executes. If the expression evaluates to a falsy value, its code body will NOT execute.
Example:
const isMailSent = true;

if (isMailSent) {
console.log(‘Mail sent to recipient’);
}

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

What is the Logical Operator “!”?

A

The logical NOT operator “!” can be used to do one of the following: Invert a Boolean value. Invert the truthiness of non-Boolean values.
Example:
let lateToWork = true;
let oppositeValue = !lateToWork;

console.log(oppositeValue);
// Prints: false

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

What are Comparison Operators?

A

Comparison operators are used to compare two values and return “true” or “false” depending on the validity of the comparison.

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

What is the “strict equal” operator?

A

===

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

What is the “strict not equal” operator?

A

!==

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

What is the “greater than” operator?

A

>

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

What is the “greater than or equal to” operator?

A

> =

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

What is the “less than” operator?

A

<

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

What is the “less than or equal to” operator?

A

<=

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

What is an “else if” Clause?

A

After an initial “if” block, “else if” blocks can each check an additional condition. An optional “else” block can be added after the “else if” block(s) to run by default if none of the conditions evaluated to truthy.
Example:
const size = 10;

if (size > 100) {
console.log(‘Big’);
} else if (size > 20) {
console.log(‘Medium’);
} else if (size > 4) {
console.log(‘Small’);
} else {
console.log(‘Tiny’);
}
// Print: Small

17
Q

What does Truthy and Falsy mean?

A

In JavaScript, values evaluate to “true” or “false” when evaluated as Booleans. Falsy values include “false”, “0”, empty strings, “null undefined”, and “NaN”. All other values are truthy.