Bird
0
0

Why does the expression $false -or $null evaluate to $null in PowerShell?

hard📝 Conceptual Q10 of 15
PowerShell - Operators
Why does the expression $false -or $null evaluate to $null in PowerShell?
ABecause -or returns the first operand always
BBecause -or returns the last operand if the first is false
CBecause $null is treated as false but returned as is
DBecause $false and $null are equivalent
Step-by-Step Solution
Solution:
  1. Step 1: Understand PowerShell's -or behavior

    -or returns the first operand if it is true; otherwise, it returns the second operand.
  2. Step 2: Apply to $false -or $null

    Since $false is false, -or returns $null, the second operand.
  3. Final Answer:

    Because -or returns the last operand if the first is false -> Option B
  4. Quick Check:

    -or returns second operand if first is false [OK]
Quick Trick: -or returns second operand if first is false [OK]
Common Mistakes:
  • Thinking -or always returns boolean
  • Confusing $null with $false
  • Assuming -or returns first operand always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes