OR, AND Operator

前端 未结 8 2097
臣服心动
臣服心动 2021-02-13 15:30

Newbie question. How to calculate the value of the formula A f B, where f - the binary function OR or AND?

8条回答
  •  鱼传尺愫
    2021-02-13 16:10

    Logical OR is ||, logical AND is &&. If you need the negation NOT, prefix your expression with !.

    Example:

    X = (A && B) || C || !D;
    

    Then X will be true when either A and B are true or if C is true or if D is not true (i.e. false).

    If you wanted bit-wise AND/OR/NOT, you would use &, | and ~. But if you are dealing with boolean/truth values, you do not want to use those. They do not provide short-circuit evaluation for example due to the way a bitwise operation works.

提交回复
热议问题