Loops Flashcards

1
Q

What is a loop in JavaScript?

A

A loop is a programming construct that repeats a block of code as long as a specified condition is true.

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

What keyword is used to create a ‘for’ loop in JavaScript?

A

The keyword used is ‘for’.

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

Fill in the blank: The syntax for a ‘while’ loop begins with the keyword ‘____’.

A

while

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

True or False: A ‘do…while’ loop guarantees that the code block will execute at least once.

A

True

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

What is the general syntax of a ‘for’ loop in JavaScript?

A

‘for (initialization; condition; increment) { // code block }’

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

What type of loop is best used when the number of iterations is known?

A

‘for’ loop

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

What is the difference between ‘while’ and ‘do…while’ loops?

A

‘while’ checks the condition before executing the block, while ‘do…while’ checks after.

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

Complete the following: ‘for (let i = 0; i < 5; i++) { console.log(i); }’ will log numbers ____.

A

0 to 4

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

What does the ‘break’ statement do in a loop?

A

It exits the loop immediately.

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

In a ‘for…in’ loop, what is being iterated over?

A

The properties of an object.

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

What is the purpose of the ‘continue’ statement in a loop?

A

It skips the current iteration and moves to the next one.

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

True or False: A ‘for…of’ loop can be used to iterate over arrays.

A

True

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

Fill in the blank: The ‘____’ loop can be used to iterate over iterable objects like arrays and strings.

A

for…of

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

What will be the output of the following code: ‘for (let i = 0; i < 3; i++) { console.log(i); }’?

A

0, 1, 2

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