Bird
0
0

Identify the error in this PowerShell code:

medium📝 Debug Q6 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell code:
$name = 'John'
$message = '$name is here'
Write-Output $message
AVariable $name is not defined
BSingle quotes prevent variable interpolation
CMissing semicolon after assignment
DWrite-Output cannot print variables
Step-by-Step Solution
Solution:
  1. Step 1: Understand single vs double quotes in PowerShell

    Single quotes treat content literally, no variable interpolation.
  2. Step 2: Analyze the output of $message

    $message will be the literal string '$name is here', not 'John is here'.
  3. Final Answer:

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

    Single quotes = no variable interpolation [OK]
Quick Trick: Use double quotes to interpolate variables [OK]
Common Mistakes:
  • Using single quotes expecting interpolation
  • Assuming variables print without $
  • Confusing syntax errors with output issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes