Bird
0
0

Identify the error in this PowerShell script:

medium📝 Debug Q14 of 15
PowerShell - Working with Objects
Identify the error in this PowerShell script:
$array = @()
$array += 'one'
$array = $array + 'two'
$array = $array + 3
$array
ANo error; script runs and outputs all items
BUsing + operator on arrays causes error
CCannot add integer to string array
DArray must be declared with fixed size
Step-by-Step Solution
Solution:
  1. Step 1: Check adding different types to array

    PowerShell arrays can hold mixed types, so adding integer 3 is allowed.
  2. Step 2: Check use of + operator on arrays

    Using + concatenates arrays or adds items; it works fine here.
  3. Final Answer:

    No error; script runs and outputs all items -> Option A
  4. Quick Check:

    PowerShell arrays accept mixed types and + works [OK]
Quick Trick: PowerShell arrays can mix types and use + to add items [OK]
Common Mistakes:
  • Thinking arrays only hold one data type
  • Believing + operator causes errors on arrays
  • Assuming arrays need fixed size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes