Bird
0
0

What will this PowerShell script output?

medium📝 Command Output Q5 of 15
PowerShell - Operators
What will this PowerShell script output?
$value = 0
$output = $value ? 'Yes' : 'No'
Write-Output $output
AYes
BNo
C0
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand how PowerShell treats 0 in condition

    In PowerShell, 0 is treated as false in a boolean context.
  2. Step 2: Apply ternary operator

    Since $value is 0 (false), the ternary operator returns the false-value 'No'.
  3. Final Answer:

    No -> Option B
  4. Quick Check:

    Falsy value returns false branch = No [OK]
Quick Trick: 0 is false in PowerShell ternary conditions [OK]
Common Mistakes:
  • Assuming 0 is true
  • Expecting numeric output
  • Confusing output with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes