Conditional Statments Flashcards

1
Q

What is a conditional statement in JavaScript?

A

A conditional statement is a programming construct that evaluates a condition and executes code based on whether the condition is true or false.

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

What is the syntax for an if statement in JavaScript?

A

The syntax for an if statement is: if (condition) { // code to execute if condition is true }

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

True or False: The else statement is optional in an if-else structure.

A

True

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

Fill in the blank: The _____ statement allows you to specify a block of code to execute if the condition is false.

A

else

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

What is the syntax for an if-else statement in JavaScript?

A

The syntax is: if (condition) { // code if true } else { // code if false }

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

What is the purpose of the else if statement?

A

The else if statement allows you to test multiple conditions sequentially.

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

What is the syntax for an if-else if-else statement?

A

The syntax is: if (condition1) { // code if condition1 is true } else if (condition2) { // code if condition2 is true } else { // code if both conditions are false }

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

True or False: You can nest if statements inside other if statements.

A

True

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

What is the switch statement used for in JavaScript?

A

The switch statement is used to execute one block of code among multiple options based on the value of an expression.

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

What is the basic syntax of a switch statement?

A

The syntax is: switch (expression) { case value1: // code; break; case value2: // code; break; default: // code; }

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

In a switch statement, what does the break keyword do?

A

The break keyword exits the switch block and prevents the execution of subsequent cases.

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

What happens if you omit the break statement in a switch case?

A

If you omit the break statement, JavaScript will continue executing subsequent cases until it encounters a break or reaches the end of the switch block.

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

What is a ternary operator in JavaScript?

A

The ternary operator is a shorthand for an if-else statement, using the syntax: condition ? exprIfTrue : exprIfFalse.

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

Fill in the blank: The syntax of a ternary operator includes _____, _____, and _____.

A

condition, exprIfTrue, exprIfFalse

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

What is the purpose of the logical operators (&&, ||, !) in conditional statements?

A

Logical operators are used to combine multiple conditions in conditional statements.

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