Bird
0
0

Find the error in this PowerShell snippet:

medium📝 Debug Q7 of 15
PowerShell - Variables and Data Types
Find the error in this PowerShell snippet:
$value = 10
$text = "Value is: $value*2"
Write-Output $text
AMissing closing quote in string
BVariable $value is undefined
CExpression $value*2 is not evaluated inside string
DWrite-Output cannot print strings
Step-by-Step Solution
Solution:
  1. Step 1: Check how expressions are evaluated in strings

    Without $(), expressions like $value*2 are not calculated inside strings.
  2. Step 2: Understand the output

    The string will show "Value is: 10*2" literally, not "Value is: 20".
  3. Final Answer:

    Expression $value*2 is not evaluated inside string -> Option C
  4. Quick Check:

    Use $() to evaluate expressions inside strings [OK]
Quick Trick: Wrap expressions in $() to evaluate inside strings [OK]
Common Mistakes:
  • Expecting expressions to auto-evaluate without $()
  • Confusing variable interpolation with expression evaluation
  • Ignoring syntax for expression evaluation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes