Bird
0
0

What will this code output?

medium📝 Command Output Q5 of 15
PowerShell - Variables and Data Types
What will this code output?
$hash = @{ 'a' = 1; 'b' = 2 }
$hash['c'] = 3
$hash['c']
A2
Bnull
CError
D3
Step-by-Step Solution
Solution:
  1. Step 1: Add a new key-value pair to the hash table

    $hash['c'] = 3 adds key 'c' with value 3 to the hash table.
  2. Step 2: Access the value for key 'c'

    $hash['c'] returns the newly added value 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Adding and accessing new key returns its value [OK]
Quick Trick: Add keys by assignment: $hash['newKey'] = value [OK]
Common Mistakes:
  • Expecting error when adding keys
  • Confusing null with missing key
  • Using wrong syntax for adding keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes