PowerShell - Variables and Data TypesWhat happens if you add duplicate keys to a PowerShell hash table during creation like @{ 'a' = 1; 'a' = 2 }?AAn error is thrown for duplicate keysBBoth values are stored as a list under the keyCThe last value overwrites the previous one for the duplicate keyDThe hash table ignores the duplicate key and keeps the first valueCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand hash table key uniquenessHash tables require unique keys; duplicates overwrite previous entries.Step 2: Analyze behavior on duplicatesPowerShell hash tables keep the last value assigned to a duplicate key, overwriting earlier ones.Final Answer:The last value overwrites the previous one for the duplicate key -> Option CQuick 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 duplicatesThinking duplicates create listsAssuming first value is kept
Master "Variables and Data Types" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Pipeline object flow - Quiz 4medium Control Flow - Break and continue - Quiz 3easy Control Flow - If-elseif-else statements - Quiz 8hard Control Flow - While and Do-While loops - Quiz 13medium PowerShell Basics and Environment - PowerShell vs Bash vs CMD comparison - Quiz 13medium PowerShell Basics and Environment - PowerShell console and ISE - Quiz 1easy PowerShell Basics and Environment - PowerShell vs Bash vs CMD comparison - Quiz 8hard PowerShell Basics and Environment - First PowerShell command - Quiz 15hard String Operations - Regular expressions with -match - Quiz 4medium Variables and Data Types - Arrays - Quiz 10hard