Bird
0
0

Which of the following is the correct syntax to interpolate the variable $name inside a string in PowerShell?

easy📝 Syntax Q12 of 15
PowerShell - Variables and Data Types
Which of the following is the correct syntax to interpolate the variable $name inside a string in PowerShell?
A"Hello, $name!"
B'Hello, $name!'
C`Hello, $name!`
DHello, $name!
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct string syntax for interpolation

    Double quotes are needed to allow variable interpolation in PowerShell strings.
  2. Step 2: Check each option

    "Hello, $name!" uses double quotes correctly; 'Hello, $name!' uses single quotes (no interpolation); `Hello, $name!` uses backticks (escape character, not string quotes); Hello, $name! is missing quotes.
  3. Final Answer:

    "Hello, $name!" -> Option A
  4. Quick Check:

    Double quotes for interpolation = A [OK]
Quick Trick: Remember: double quotes for variables inside strings [OK]
Common Mistakes:
  • Using single quotes expecting variable to expand
  • Using backticks as string delimiters
  • Omitting quotes around strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes