Bird
0
0

Which of the following is the correct syntax for the ternary operator in PowerShell 7+?

easy📝 Syntax Q12 of 15
PowerShell - Operators
Which of the following is the correct syntax for the ternary operator in PowerShell 7+?
Acondition ? true-value : false-value
Bif (condition) { true-value } else { false-value }
Ccondition ? true-value, false-value
Dcondition : true-value ? false-value
Step-by-Step Solution
Solution:
  1. Step 1: Recall the ternary operator syntax

    The ternary operator uses the format: condition ? true-value : false-value.
  2. Step 2: Compare options

    'if (condition) { true-value } else { false-value }' is an if-else statement, not ternary. 'condition ? true-value, false-value' uses comma instead of colon. 'condition : true-value ? false-value' has question mark and colon swapped. Only 'condition ? true-value : false-value' matches exactly.
  3. Final Answer:

    condition ? true-value : false-value -> Option A
  4. Quick Check:

    Correct ternary syntax = condition ? true : false [OK]
Quick Trick: Look for question mark then colon in correct order [OK]
Common Mistakes:
  • Using commas instead of colon
  • Swapping question mark and colon
  • Using if-else instead of ternary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes