Skip to content

Latest commit

 

History

History
32 lines (21 loc) · 871 Bytes

File metadata and controls

32 lines (21 loc) · 871 Bytes

Operators -and and -or have the same precedence

Logical operators -and and -or have the same precedence, unlike in other programming languages where logical AND has higher precedence.

This C# expression is evaluated to true

    true || true && false

This similar PowerShell expression is evaluated to false

    $true -or $true -and $false

To avoid this trap, especially on translating code from other languages to PowerShell, use parenthesis

    $true -or ($true -and $false)

Scripts