javascript-loops Flashcards

1
Q

What is the purpose of a loop?

A

Loops offer a quick and easy way to do something repeatedly.

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

What is the purpose of a condition expression in a loop?

A

condition
An expression to be evaluated before each loop iteration. If this expression evaluates to true, statement is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the for construct.

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

What does “iteration” mean in the context of loops?

A

run of the loop

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

When does the condition expression of a while loop get evaluated?

A

condition
An expression evaluated before each pass through the loop. If this condition evaluates to true, statement is executed. When condition evaluates to false, execution continues with the statement after the while loop.

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

When does the initialization expression of a for loop get evaluated?

A
initialization
An expression (including assignment expressions) or variable declaration evaluated once before the loop begins. Typically used to initialize a counter variable. This expression may optionally declare new variables with var or let keywords. Variables declared with var are not local to the loop, i.e. they are in the same scope the for loop is in. Variables declared with let are local to the statement.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When does the condition expression of a for loop get evaluated?

A

condition
An expression to be evaluated before each loop iteration. If this expression evaluates to true, statement is executed. This conditional test is optional. If omitted, the condition always evaluates to true. If the expression evaluates to false, execution skips to the first expression following the for construct.

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

When does the final expression of a for loop get evaluated?

A

final-expression
An expression to be evaluated at the end of each loop iteration. This occurs before the next evaluation of condition. Generally used to update or increment the counter variable.

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

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

Use the break statement to stop a loop before condition evaluates to true

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

What does the ++ increment operator do?

A

The increment operator (++) increments (adds one to) its operand and returns a value.

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

How do you iterate through the keys of an object?

A

Iterate (loop) over the properties of an object:

constperson = {fname:"John", lname:"Doe", age:25};
let text = "";
for (let x in person) {
  text += person[x] + " ";
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly