Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Variables and Data Types
What will be the output of this PowerShell code?
$hash = @{ 'a' = 1; 'b' = 2 }
$hash['a'] = 3
$hash['c'] = 4
$hash['b']
A2
B1
C3
D4
Step-by-Step Solution
Solution:
  1. Step 1: Understand the initial hash table and updates

    The hash table starts with keys 'a' = 1 and 'b' = 2. Then 'a' is updated to 3, and a new key 'c' = 4 is added.
  2. Step 2: Identify the value accessed

    The code outputs $hash['b'], which was never changed and remains 2.
  3. Final Answer:

    2 -> Option A
  4. Quick Check:

    Access unchanged key 'b' = 2 [OK]
Quick Trick: Check which key is accessed after updates [OK]
Common Mistakes:
  • Confusing updated key 'a' with accessed key 'b'
  • Assuming last added key 'c' is accessed
  • Mixing values of different keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes