PowerShell - OperatorsWhich of these is a valid use of the ternary operator in PowerShell 7+?A$x = 5; if ($x -gt 3) { 'Yes' } else { 'No' }B$x = 5; $result = $x -gt 3 ? 'Yes' : 'No'C$x = 5; $result = if $x -gt 3 then 'Yes' else 'No'D$x = 5; $result = $x gt 3 ? 'Yes' : 'No'Check Answer
Step-by-Step SolutionSolution:Step 1: Check PowerShell ternary syntaxPowerShell uses the syntax: condition ? true-value : false-value. $x = 5; $result = $x -gt 3 ? 'Yes' : 'No' matches this exactly.Step 2: Identify incorrect syntax in other options$x = 5; if ($x -gt 3) { 'Yes' } else { 'No' } uses if-else block, not ternary. $x = 5; $result = if $x -gt 3 then 'Yes' else 'No' uses invalid keywords 'then' and 'else'. $x = 5; $result = $x gt 3 ? 'Yes' : 'No' uses 'gt' which is invalid in PowerShell (requires '-gt').Final Answer:$x = 5; $result = $x -gt 3 ? 'Yes' : 'No' -> Option BQuick Check:Valid ternary syntax = $x = 5; $result = $x -gt 3 ? 'Yes' : 'No' [OK]Quick Trick: Use -gt, not >, with ternary in PowerShell [OK]Common Mistakes:Using gt without dash for comparisonMixing if-else block with ternary syntaxUsing invalid keywords like then
Master "Operators" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Verb-Noun naming convention - Quiz 1easy Cmdlets and Pipeline - Pipeline object flow - Quiz 9hard Cmdlets and Pipeline - Pipeline object flow - Quiz 8hard Cmdlets and Pipeline - Select-Object for properties - Quiz 11easy Operators - Logical operators (-and, -or, -not) - Quiz 10hard Operators - Range operator (..) - Quiz 3easy Operators - Range operator (..) - Quiz 14medium PowerShell Basics and Environment - PowerShell versions (5.1 vs 7+) - Quiz 8hard Variables and Data Types - Automatic variables ($_, $PSVersionTable) - Quiz 10hard Variables and Data Types - Hash tables (dictionaries) - Quiz 14medium