Bird
0
0

Which of the following is a valid variable name in PowerShell?

easy📝 Syntax Q3 of 15
PowerShell - Variables and Data Types
Which of the following is a valid variable name in PowerShell?
A$user-name
B$userName
C$123name
D$user name
Step-by-Step Solution
Solution:
  1. Step 1: Understand PowerShell variable naming rules

    Variable names must start with a letter or underscore after the $, and cannot contain spaces or hyphens.
  2. Step 2: Evaluate each option

    $userName is valid: starts with letter and no spaces/hyphens. Options A, B, and D violate naming rules.
  3. Final Answer:

    $userName -> Option B
  4. Quick Check:

    Valid variable names start with letter or underscore [OK]
Quick Trick: Variable names: letters, digits, underscore; no spaces or hyphens [OK]
Common Mistakes:
  • Starting variable names with digits
  • Including spaces or hyphens in names
  • Using special characters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes