Bird
0
0

Which of the following is the correct way to create an empty array in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Variables and Data Types
Which of the following is the correct way to create an empty array in PowerShell?
A$arr = []
B$arr = array()
C$arr = {}
D$arr = @()
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell array syntax

    PowerShell uses @() to create arrays, including empty ones.
  2. Step 2: Check each option

    $arr = @() uses @() which is correct. Options A, B, and C use invalid or different syntax for arrays.
  3. Final Answer:

    $arr = @() -> Option D
  4. Quick Check:

    Empty array = @() [OK]
Quick Trick: Use @() to create arrays in PowerShell [OK]
Common Mistakes:
  • Using [] which is not valid for arrays in PowerShell
  • Using {} which is for hashtables or script blocks
  • Using array() which is not recognized in PowerShell

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes