Bird
0
0

Which of the following is the correct way to define a function in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Functions
Which of the following is the correct way to define a function in PowerShell?
Afunction MyFunc { Write-Output 'Hello' }
Bdef MyFunc() { Write-Output 'Hello' }
Cfunc MyFunc() => Write-Output 'Hello'
Dfunction:MyFunc { echo 'Hello' }
Step-by-Step Solution
Solution:
  1. Step 1: Recall PowerShell function syntax

    PowerShell functions start with the keyword 'function' followed by the name and braces.
  2. Step 2: Check each option's syntax

    function MyFunc { Write-Output 'Hello' } uses correct PowerShell syntax; others use syntax from other languages or invalid forms.
  3. Final Answer:

    function MyFunc { Write-Output 'Hello' } -> Option A
  4. Quick Check:

    PowerShell function syntax = function MyFunc { Write-Output 'Hello' } [OK]
Quick Trick: PowerShell functions start with 'function' keyword [OK]
Common Mistakes:
  • Using Python or JavaScript syntax instead
  • Using colons instead of braces
  • Using 'def' or 'func' keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes