PowerShell - Variables and Data TypesWhich of the following is the correct way to assign a Boolean value to a variable in PowerShell?A$flag = $trueB$flag = TrueC$flag := $trueD$flag == $trueCheck Answer
Step-by-Step SolutionSolution:Step 1: Recall Boolean value syntaxPowerShell Boolean literals are '$true' and '$false' with a dollar sign and lowercase.Step 2: Check assignment syntaxAssignment uses '=', so '$flag = $true' is correct. Other options use invalid syntax or missing '$'.Final Answer:$flag = $true -> Option AQuick Check:Assign Boolean with '$true' and '=' [OK]Quick Trick: Use '$true' and '=' to assign Booleans [OK]Common Mistakes:Omitting the '$' in Boolean literalsUsing ':=' or '==' for assignmentCapitalizing 'True' without '$'
Master "Variables and Data Types" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Where-Object for filtering - Quiz 11easy Cmdlets and Pipeline - Get-Member for object inspection - Quiz 2easy Control Flow - For loop - Quiz 10hard Control Flow - For loop - Quiz 15hard Operators - Range operator (..) - Quiz 11easy Operators - Why operators perform comparisons and logic - Quiz 11easy PowerShell Basics and Environment - Command discovery (Get-Command) - Quiz 2easy PowerShell Basics and Environment - First PowerShell command - Quiz 2easy String Operations - Select-String for searching - Quiz 10hard Variables and Data Types - Why variables store data - Quiz 15hard