Bird
0
0

Consider this function:

hard📝 Application Q9 of 15
PowerShell - Functions
Consider this function:
function Calculate { param([int]$a = 10, [int]$b = 20) $a + $b }

How would you call it to use the default for 'a' but pass 5 for 'b'?
ACalculate 5
BCalculate -b 5
CCalculate -a 10 -b 5
DCalculate -a 5
Step-by-Step Solution
Solution:
  1. Step 1: Understand default and named parameters

    To use default 'a' and custom 'b', pass only '-b 5'.
  2. Step 2: Analyze options

    Calculate -b 5 passes '-b 5' only; others override 'a' or pass positional.
  3. Final Answer:

    Calculate -b 5 -> Option B
  4. Quick Check:

    Named param lets you skip default params [OK]
Quick Trick: Use named parameters to skip defaults [OK]
Common Mistakes:
  • Passing positional argument changes 'a'
  • Passing both parameters unnecessarily
  • Not using named parameter for 'b'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes