Bird
0
0

Which of the following is the correct way to assign a Boolean value to a variable in PowerShell?

easy📝 Syntax Q3 of 15
PowerShell - Variables and Data Types
Which of the following is the correct way to assign a Boolean value to a variable in PowerShell?
A$flag = $true
B$flag = True
C$flag := $true
D$flag == $true
Step-by-Step Solution
Solution:
  1. Step 1: Recall Boolean value syntax

    PowerShell Boolean literals are '$true' and '$false' with a dollar sign and lowercase.
  2. Step 2: Check assignment syntax

    Assignment uses '=', so '$flag = $true' is correct. Other options use invalid syntax or missing '$'.
  3. Final Answer:

    $flag = $true -> Option A
  4. Quick Check:

    Assign Boolean with '$true' and '=' [OK]
Quick Trick: Use '$true' and '=' to assign Booleans [OK]
Common Mistakes:
  • Omitting the '$' in Boolean literals
  • Using ':=' or '==' for assignment
  • Capitalizing 'True' without '$'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes