Bird
0
0

Why does the += operator update the original variable instead of creating a new one in PowerShell?

hard📝 Conceptual Q10 of 15
PowerShell - Operators
Why does the += operator update the original variable instead of creating a new one in PowerShell?
ABecause PowerShell does not allow variable reassignment
BBecause it creates a new variable with the same name
CBecause it only works with constants
DBecause it performs an in-place addition and assignment to the same variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand += behavior

    The += operator adds the right-hand value to the current variable value and assigns the result back to the same variable.
  2. Step 2: Clarify variable reassignment

    It does not create a new variable but updates the existing one in place.
  3. Final Answer:

    Because it performs an in-place addition and assignment to the same variable -> Option D
  4. Quick Check:

    += updates variable in place, no new variable created [OK]
Quick Trick: += adds and updates same variable in place [OK]
Common Mistakes:
  • Thinking it creates new variable
  • Believing reassignment is disallowed
  • Assuming it only works with constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes