Flow Control Flashcards

1
Q

What is the return value of a && or || comparison?

A

When using&&and||, the return value is always the value of the operand evaluated last: This is usually a truthy or falsy value.

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

In && and || comparisons, are both sides always evaluated?

A

In a && comparison, if the program determines thatitem1is not true, it doesn’t have to check whether item2 is true. Likewise, in a || comparison, if item1 is true, the program does not need to check item2.

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

What is the syntax for the ternary operator?

A

let isOk = (foo || bar) ? true : false;

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

How can we use short circuiting to prevent an error from being thrown?

A

if (name && name.length > 0) {
console.log(Hi, ${name}.);
} else {
console.log(“Hello, whoever you are.”);
}

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

What is the nullish coalescing operator?

A

Thenullish coalescing operatorevaluates to the right-hand operand if the left-hand operand isnullish(eithernullorundefined). Otherwise, it evaluates to the value of the left-hand operand.

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

What is the syntax for the nullish coalescing operator?

A

??

function foo(str) {
let found = [“Pete”, “Alli”, “Chris”].find(name => name === str);
return found ?? “Not found”;
}

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

When should you use the ternary operator?

A

Ternary expressions should usually be used to select between 2 values, not to choose between two actions.

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

Can you treat a ternary operator like a value?

A

the entire structure is an expression so we can treat it like a value.

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

what is the order of operator precedence?

A

The following is a list of the comparison operations from the highest precedence (top) to lowest (bottom).

  • <=,<,>,>=- Comparison
  • ===,!==,==,!=- Equality
  • &&- Logical AND
  • ||- Logical OR
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the difference between the pre-increment operator ++i and the post increment operator i++?

A

pre-increment form returns the new value of the variable, while the post-increment form returns the previous value of the variable.

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

What are the keywords you can use to interrupt a loop? How are they different?

A

JavaScript uses the keywordscontinueandbreakto provide more control over loops.continuelets you start a new iteration of the loop, whilebreaklets you terminate a loop early.

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