Boolean logic in conditionals Quiz

Test your understanding of Boolean logic in conditionals, including operator precedence, associativity, short-circuit evaluation, and techniques for preventing null or undefined access. Assess your skills in writing safe, efficient logical expressions with u0026u0026, ||, and !.

  1. Operator Precedence in Conditionals

    In the expression 'true || false u0026u0026 false', which part is evaluated first according to Boolean operator precedence?

    1. false || false
    2. true u0026u0026 false
    3. false u0026u0026 false
    4. true || false
  2. Short-circuit Evaluation with u0026u0026

    Given the expression 'false u0026u0026 someFunction()', what happens to 'someFunction()' during evaluation?

    1. It is not evaluated due to short-circuiting
    2. It returns true automatically
    3. It causes an error
    4. It is always evaluated
  3. Short-circuiting to Prevent Null Access

    How can short-circuit evaluation using 'u0026u0026' help prevent errors when accessing a property of a potentially null object, as in 'obj u0026u0026 obj.value'?

    1. It forces 'obj' to be non-null
    2. It always throws an exception if 'obj' is null
    3. It avoids accessing 'value' if 'obj' is null
    4. It converts null to false automatically
  4. Logical NOT Usage

    What is the result of applying the logical NOT operator to 'true', as in '!true'?

    1. null
    2. undefined
    3. true
    4. false
  5. Associativity of Boolean Operators

    When evaluating 'a u0026u0026 b u0026u0026 c', in which order are the operations grouped due to associativity?

    1. All at the same time
    2. a u0026u0026 (b u0026u0026 c)
    3. (a u0026u0026 c) u0026u0026 b
    4. (a u0026u0026 b) u0026u0026 c
  6. Preventing Side Effects in Short-circuit Evaluation

    Why should you avoid putting expressions with side effects on the right side of 'u0026u0026' if the left side may be false?

    1. Because they always run regardless
    2. Because they may never run due to short-circuiting
    3. Because they invert the result
    4. Because they change the operator's meaning
  7. Evaluating '||' with Truthy Expressions

    What is the result of '0 || 'hello'' in a language where 0 is false and 'hello' is true?

    1. true
    2. 0
    3. false
    4. 'hello'
  8. Operator Precedence Between u0026u0026 and ||

    Which has higher precedence in Boolean expressions: 'u0026u0026' or '||'?

    1. 'u0026u0026'
    2. '||'
    3. Both are equal
    4. '!'
  9. Safe Property Access Using Conditionals

    Given 'if (item u0026u0026 item.active)', which scenario will safely prevent a runtime error?

    1. If 'item' is undefined, 'item.active' is always checked
    2. It throws an error if 'item' is undefined
    3. If 'item' is undefined, 'item.active' is not accessed
    4. It forces 'item' to become active
  10. Double NOT for Boolean Conversion

    What does applying double logical NOT, as in '!!value', achieve in Boolean logic?

    1. It causes a syntax error
    2. It converts 'value' to its Boolean equivalent
    3. It negates the value twice and always returns null
    4. It always sets 'value' to false