Bird
0
0

You have variables $firstName = "Jane" and $lastName = "Doe". Which PowerShell command correctly concatenates these with a space and outputs the full name?

hard📝 Application Q8 of 15
PowerShell - String Operations
You have variables $firstName = "Jane" and $lastName = "Doe". Which PowerShell command correctly concatenates these with a space and outputs the full name?
AWrite-Output "$firstName $lastName"
BWrite-Output $firstName + $lastName
CWrite-Output '$firstName $lastName'
DWrite-Output $firstName -join ' ' - $lastName
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation

    Double quotes allow variable expansion in PowerShell.
  2. Step 2: Check concatenation with space

    Using "$firstName $lastName" inserts a space between the variables.
  3. Step 3: Analyze other options

    Write-Output $firstName + $lastName concatenates without space; C uses single quotes (no expansion); D uses invalid syntax.
  4. Final Answer:

    Write-Output "$firstName $lastName" -> Option A
  5. Quick Check:

    Use double quotes for variable expansion with spaces [OK]
Quick Trick: Use double quotes for variable expansion with spaces. [OK]
Common Mistakes:
  • Using single quotes which prevent variable expansion.
  • Concatenating without adding a space.
  • Using invalid operators like '-join' incorrectly.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes