Bird
0
0

Identify the error in this PowerShell snippet:

medium📝 Debug Q6 of 15
PowerShell - Variables and Data Types
Identify the error in this PowerShell snippet:
if ($true and $false) { "Yes" }
A'and' should be '-and'
BMissing 'else' block
CBoolean values must be uppercase
DQuotes missing around Boolean values
Step-by-Step Solution
Solution:
  1. Step 1: Check logical operator syntax

    PowerShell uses '-and' for logical AND, not 'and'.
  2. Step 2: Identify the error

    Using 'and' causes a syntax error; it must be '-and'.
  3. Final Answer:

    'and' should be '-and' -> Option A
  4. Quick Check:

    Logical AND operator is '-and' [OK]
Quick Trick: Use '-and' not 'and' for logical AND [OK]
Common Mistakes:
  • Using 'and' instead of '-and'
  • Thinking 'and' is valid PowerShell syntax
  • Ignoring operator syntax rules

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes