'AND' vs '&&' as operator

后端 未结 10 843
野性不改
野性不改 2020-11-22 02:42

I have a codebase where developers decided to use AND and OR instead of && and ||.

I know that there is a

10条回答
  •  梦谈多话
    2020-11-22 03:26

    Precedence differs between && and and (&& has higher precedence than and), something that causes confusion when combined with a ternary operator. For instance,

    $predA && $predB ? "foo" : "bar"
    

    will return a string whereas

    $predA and $predB ? "foo" : "bar"
    

    will return a boolean.

提交回复
热议问题