Bird
0
0

Which of the following is the correct way to define a parameter with a default value of 5 in a PowerShell function?

easy📝 Conceptual Q2 of 15
PowerShell - Functions
Which of the following is the correct way to define a parameter with a default value of 5 in a PowerShell function?
Aparam([int]$count : 5)
Bparam([int]$count => 5)
Cparam([int]$count <- 5)
Dparam([int]$count = 5)
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell parameter default syntax

    PowerShell uses '=' to assign default values in param blocks.
  2. Step 2: Check each option

    Only param([int]$count = 5) uses '=' correctly; others use invalid symbols.
  3. Final Answer:

    param([int]$count = 5) -> Option D
  4. Quick Check:

    Default value syntax = '=' [OK]
Quick Trick: Use '=' to assign default values in param block [OK]
Common Mistakes:
  • Using ':' or '=>' instead of '='
  • Confusing syntax with other languages
  • Omitting the '=' sign

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes