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
and
That与
并且
means, so only if表达式1
and表达式2
are correct (that is, are truetrue
time), the return value is onlytrue
;- 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
表达式1
isfalse
the time, it is the result of the operationfalse
(表达式2
what do not read, the equivalent of direct ignored), or just the value of the operation result of表达式2
the result of consistent - This phenomenon is also known as
短路运算
Want a deeper understanding of their own short-circuit operation of children's shoes welcome
Google
Kazakhstan
Logical OR operator (||)
- grammar:
运算结果 = 表达式1 || 表达式2
- Calculation result can be any variable that corresponds to a container, the result is placed inside the container
or
That或者
means, so long as when表达式1
and表达式2
which have an expression returns a valuetrue
, it is the result of the operationtrue
; only when both expressions arefalse
time, 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
astrue
when the operation result istrue
(poor expression 2, and it was ruthlessly ignored - _ -); otherwise, just like the value of the operation result of表达式2
the 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 millionHere 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 true
who isfalse
Can be converted into false
an 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