Bird
0
0

Which of the following is the correct syntax to create a hash table with keys 'Name' and 'Age'?

easy📝 Syntax Q3 of 15
PowerShell - Variables and Data Types
Which 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)
Step-by-Step Solution
Solution:
  1. Step 1: Recall the hash table creation syntax in PowerShell

    Hash tables are created using @{} with key = value pairs separated by semicolons.
  2. 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.
  3. Final Answer:

    $hash = @{ Name = 'John'; Age = 30 } -> Option B
  4. Quick Check:

    Create hash table = @{ key = value; ... } [OK]
Quick Trick: Use @{} with key = value pairs separated by semicolons [OK]
Common Mistakes:
  • Using commas instead of semicolons
  • Using square brackets instead of @{}
  • Using colons or arrows incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes