Bird
0
0

Why does the expression ($x -eq 0) return false when $x is $null in PowerShell?

hard📝 Conceptual Q10 of 15
PowerShell - Operators
Why does the expression ($x -eq 0) return false when $x is $null in PowerShell?
ABecause -eq operator only works with numbers
BBecause -eq treats $null as zero
CBecause PowerShell converts $null to zero automatically
DBecause $null is not equal to zero
Step-by-Step Solution
Solution:
  1. Step 1: Understand data types in comparison

    $null is a special value representing absence of any object, not a number.
  2. Step 2: Evaluate the comparison behavior

    Comparing $null to 0 with -eq returns false because $null is not equal to 0.
  3. Final Answer:

    Because $null is not equal to zero -> Option D
  4. Quick Check:

    $null != 0, so -eq returns false [OK]
Quick Trick: $null is not zero; they are not equal [OK]
Common Mistakes:
  • Assuming $null equals zero
  • Thinking -eq converts types automatically
  • Believing -eq only works with numbers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes