Logical operators · JavaScript whole stack

This section learning objectives

  • Master &&, ||, !logical operators arithmetic rule

This Section

Logical AND operator (&&)

Two expressions for performing a logical AND operation (and equivalent English meaning)

  • grammar: 运算结果 = 表达式1 && 表达式2
    • Calculation result can be any variable that corresponds to a container, the result is placed inside the container
    • andThat 并且means, so only if 表达式1and 表达式2are correct (that is, are true truetime), the return value is only true;
    • Expressed as a list:
Operation result Expression 1 Expression 2
true true true
false true false
false false true
false false false
  • We can see from the table above it, when 表达式1is falsethe time, it is the result of the operation false( 表达式2what do not read, the equivalent of direct ignored), or just the value of the operation result of 表达式2the result of consistent
  • This phenomenon is also known as 短路运算

    Want a deeper understanding of their own short-circuit operation of children's shoes welcome GoogleKazakhstan

Logical OR operator (||)
  • grammar: 运算结果 = 表达式1 || 表达式2
    • Calculation result can be any variable that corresponds to a container, the result is placed inside the container
    • orThat 或者means, so long as when 表达式1and 表达式2which have an expression returns a value true, it is the result of the operation true; only when both expressions are falsetime, is the result of the operationfalse
    • Expressed as a list:
Operation result Expression 1 Expression 2
true true true
true true false
true false true
false false false
  • We can see from the table above it, as long表达式1 as truewhen the operation result is true(poor expression 2, and it was ruthlessly ignored - _ -); otherwise, just like the value of the operation result of 表达式2the result of consistent
  • This phenomenon we mentioned above, with the logical product &&is the same phenomenon, should remember it, a phenomenon called短路运算
Logical NOT operator (!)

To perform a logical expression used to reverse

  • grammar: 运算结果 = !表达式

    • Meaning the operation result with the above two are the same Ha
    • Is 不是 否定the meaning of the expression with the result so contrary thousand million

      Here you can use to explain the very image of the argument: the face of mischievous troublemaker mothers often smiled and say: let your bias you east to west (^ _ ^) think of "Three Kingdoms" in his comment: big evil like loyalty, really big pseudolikelihood

    • Expressed as a list:

Operation result Expression 1
true false
false true
Who is truewho isfalse

Can be converted into falsean expression are: null, NaN, 0, 空字符串(""),undefined

The specific reasons for it, now do not get to the bottom of Kazakhstan

Other recommended information:

This section exercise

  • Write result of a logical expression of the following:
    • "hello" && 88
    • null && 66
    • " " || 88
    • undefined || true
    • !" "
    • !8866

Original: Big Box  logical operators · JavaScript whole stack


Guess you like

Origin www.cnblogs.com/petewell/p/11611810.html