Bird
0
0

What happens if you add duplicate keys to a PowerShell hash table during creation like @{ 'a' = 1; 'a' = 2 }?

hard📝 Conceptual Q10 of 15
PowerShell - Variables and Data Types
What happens if you add duplicate keys to a PowerShell hash table during creation like @{ 'a' = 1; 'a' = 2 }?
AAn error is thrown for duplicate keys
BBoth values are stored as a list under the key
CThe last value overwrites the previous one for the duplicate key
DThe hash table ignores the duplicate key and keeps the first value
Step-by-Step Solution
Solution:
  1. Step 1: Understand hash table key uniqueness

    Hash tables require unique keys; duplicates overwrite previous entries.
  2. Step 2: Analyze behavior on duplicates

    PowerShell hash tables keep the last value assigned to a duplicate key, overwriting earlier ones.
  3. Final Answer:

    The last value overwrites the previous one for the duplicate key -> Option C
  4. Quick Check:

    Duplicate keys overwrite previous values in hash tables [OK]
Quick Trick: Duplicate keys overwrite previous values in hash tables [OK]
Common Mistakes:
  • Expecting error on duplicates
  • Thinking duplicates create lists
  • Assuming first value is kept

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes