Free Practice Quiz Question List

3 Conditionals and Boolean Logic Online Quiz Questions

Use this free practice quiz with 20 questions to review 3 Conditionals and Boolean Logic, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: In JavaScript, an empty array is truthy when it is evaluated as the condition of an if statement.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Which JavaScript expression evaluates to true because it allows type conversion between a number and a string?

  1. A

    5 === "5"

  2. B

    5 == "5"

  3. C

    5 !== "5"

  4. D

    5 === 5

03
Fill in the blank
1 point

Complete the statement: To require that a customer is a member has spent at least $50, combine the two conditions with the JavaScript operator shown in the blank.

04
Written response
1 point

What JavaScript term describes a non-Boolean value that behaves like true when used as an if condition?

05
Choose one
1 point

Given const user = null;, what happens in if (user && user.name) { ... }?

  1. A

    It throws an error while evaluating user.name.

  2. B

    It skips evaluating user.name.

  3. C

    It changes user into an empty object.

  4. D

    It evaluates user.name and returns undefined.

06
True or false
1 point

True or false: If a program checks age >= 18 before age >= 65 in an else if chain, the senior branch can still run for an age of 70.

  1. A

    True

  2. B

    False

07
Fill in the blank
1 point

Complete the statement: The JavaScript operator that reverses a Boolean condition is .

08
Choose all
1 point

Which values are falsy in JavaScript? Select all correct choices.

  1. A

    0

  2. B

    ""

  3. C

    null

  4. D

    undefined

  5. E

    NaN

  6. F

    []

09
Written response
1 point

What string is assigned to displayName by this code? const enteredName = ""; const displayName = enteredName || "Guest";

10
Choose one
1 point

Which JavaScript condition correctly implements this rule: a discount applies when a customer is a member who spends at least $50, or when the customer has a promotional code?

  1. A

    (isMember && purchaseTotal >= 50) || hasPromoCode

  2. B

    isMember || purchaseTotal >= 50 || hasPromoCode

  3. C

    isMember && (purchaseTotal >= 50 || hasPromoCode)

  4. D

    (isMember || purchaseTotal >= 50) && hasPromoCode

11
Choose all
1 point

Which practices help make JavaScript conditional logic clearer or less error-prone? Select all correct choices.

  1. A

    Prefer === and !== for comparisons by default.

  2. B

    Use braces around conditional branches.

  3. C

    Test values just below, exactly at, and just above a limit.

  4. D

    Use score = 10 when you need to test whether score equals 10.

12
Open ended
1 point

Explain a reliable process for designing and checking a JavaScript conditional that has multiple requirements and boundary values. Include one correctly grouped Boolean expression as an example.

13
Choose one
1 point

What does this code print when age is 70?

if (age >= 65) { console.log("Senior"); } else if (age >= 18) { console.log("Adult"); } else { console.log("Minor"); }

  1. A

    It prints Minor.

  2. B

    It prints Adult.

  3. C

    It prints Senior.

  4. D

    It prints nothing because both conditions are true.

14
Choose one
1 point

Which value is truthy in JavaScript?

  1. A

    0

  2. B

    ""

  3. C

    []

  4. D

    null

15
True or false
1 point

True or false: In JavaScript, user && user.name safely avoids attempting to read name when user is null.

  1. A

    True

  2. B

    False

16
Choose one
1 point

What is the result of the JavaScript expression 18 === "18"?

  1. A

    true

  2. B

    false

  3. C

    It throws an error

  4. D

    It returns the string "false"

17
Written response
1 point

Which JavaScript logical operator requires both conditions to be true?

18
Choose one
1 point

Given isMember = true, purchaseTotal = 35, and hasPromoCode = false, what is the value of (isMember && purchaseTotal >= 50) || hasPromoCode?

  1. A

    true

  2. B

    false

  3. C

    It evaluates to the purchase total, 35

  4. D

    It evaluates to the string "No"

19
Choose one
1 point

Which if...else if...else chain correctly labels a person who is 65 or older as Senior, a person aged 18 through 64 as Adult, and anyone younger than 18 as Minor?

  1. A

    if (age >= 65) { console.log("Senior"); } else if (age >= 18) { console.log("Adult"); } else { console.log("Minor"); }

  2. B

    if (age >= 18) { console.log("Adult"); } else if (age >= 65) { console.log("Senior"); } else { console.log("Minor"); }

  3. C

    if (age < 18) { console.log("Minor"); } else if (age < 65) { console.log("Senior"); } else { console.log("Adult"); }

  4. D

    if (age >= 65) { console.log("Adult"); } else if (age >= 18) { console.log("Senior"); } else { console.log("Minor"); }

20
Written response
1 point

Which JavaScript operator assigns a fallback only when the left operand is null or undefined?