Bird
0
0

Why does this PowerShell code output the literal string instead of interpolating the variable?

hard📝 Conceptual Q10 of 15
PowerShell - Variables and Data Types
Why does this PowerShell code output the literal string instead of interpolating the variable?
$var = "test"
$str = '@var is here'
Write-Output $str
AVariable $var is not defined
BSingle quotes prevent variable interpolation
CMissing $ before var in string
DWrite-Output cannot print variables
Step-by-Step Solution
Solution:
  1. Step 1: Understand single vs double quotes in PowerShell

    Single quotes treat the string literally, no variable interpolation occurs.
  2. Step 2: Analyze the output

    The string '@var is here' prints exactly as is, without replacing $var.
  3. Final Answer:

    Single quotes prevent variable interpolation -> Option B
  4. Quick Check:

    Single quotes = no variable interpolation [OK]
Quick Trick: Use double quotes for variable interpolation [OK]
Common Mistakes:
  • Using single quotes expecting interpolation
  • Forgetting $ before variable name
  • Confusing literal strings with interpolated strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes