PowerShell - Variables and Data TypesWhich of the following is the correct syntax to create a hash table with keys 'Name' and 'Age'?A$hash = [Name='John', Age=30]B$hash = @{ Name = 'John'; Age = 30 }C$hash = { 'Name' : 'John', 'Age' : 30 }D$hash = (Name => 'John', Age => 30)Check Answer
Step-by-Step SolutionSolution:Step 1: Recall the hash table creation syntax in PowerShellHash tables are created using @{} with key = value pairs separated by semicolons.Step 2: Check each option$hash = @{ Name = 'John'; Age = 30 } matches the correct syntax. Options B, C, and D use invalid syntax for PowerShell hash tables.Final Answer:$hash = @{ Name = 'John'; Age = 30 } -> Option BQuick Check:Create hash table = @{ key = value; ... } [OK]Quick Trick: Use @{} with key = value pairs separated by semicolons [OK]Common Mistakes:Using commas instead of semicolonsUsing square brackets instead of @{}Using colons or arrows incorrectly
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