Learning/Javascript
논리연산자 && || !
leanNet
2021. 1. 31. 14:07
1. &&
AND 연산
a && b
a가 true면 b, a가 false면 a
2. ||
OR 연산
a || b
a가 true면 a, a가 false면 b
2. !
NOT 연산
!a
a를 true로 변환할 수 있으면 false를 반환. 그렇지 않으면 true를 반환
false 변환할 수 있는 표현의 예는 다음과 같습니다.
- null
- NaN
- 0
- 빈 문자열 ("", '', ``)
- undefined
연산자 우선순위
다음 표는 가장 높은 우선 순위 (21)에서 가장 낮은 우선 순위 (1)로 정렬되어 있습니다.
Precedence | Operator type | Associativity | Individual operators |
21 | Grouping | n/a | ( … ) |
20 | Member Access | left-to-right | … . … |
Computed Member Access | left-to-right | … [ … ] | |
new (with argument list) | n/a | new … ( … ) | |
Function Call | left-to-right | … ( … ) | |
Optional chaining | left-to-right | ?. | |
19 | new (without argument list) | right-to-left | new … |
18 | Postfix Increment | n/a | … ++ |
Postfix Decrement | … -- | ||
17 | Logical NOT (!) | right-to-left | ! … |
Bitwise NOT (~) | ~ … | ||
Unary plus (+) | + … | ||
Unary negation (-) | - … | ||
Prefix Increment | ++ … | ||
Prefix Decrement | -- … | ||
typeof | typeof … | ||
void | void … | ||
delete | delete … | ||
await | await … | ||
16 | Exponentiation (**) | right-to-left | … ** … |
15 | Multiplication (*) | left-to-right | … * … |
Division (/) | … / … | ||
Remainder (%) | … % … | ||
14 | Addition (+) | left-to-right | … + … |
Subtraction (-) | … - … | ||
13 | Bitwise Left Shift (<<) | left-to-right | … << … |
Bitwise Right Shift (>>) | … >> … | ||
Bitwise Unsigned Right Shift (>>>) | … >>> … | ||
12 | Less Than (<) | left-to-right | … < … |
Less Than Or Equal (<=) | … <= … | ||
Greater Than (>) | … > … | ||
Greater Than Or Equal (>=) | … >= … | ||
in | … in … | ||
instanceof | … instanceof … | ||
11 | Equality (==) | left-to-right | … == … |
Inequality (!=) | … != … | ||
Strict Equality (===) | … === … | ||
Strict Inequality (!==) | … !== … | ||
10 | Bitwise AND (&) | left-to-right | … & … |
9 | Bitwise XOR (^) | left-to-right | … ^ … |
8 | Bitwise OR (|) | left-to-right | … | … |
7 | Logical AND (&&) | left-to-right | … && … |
6 | Logical OR (||) | left-to-right | … || … |
5 | Nullish coalescing operator (??) | left-to-right | … ?? … |
4 | Conditional (ternary) operator | right-to-left | … ? … : … |
3 | Assignment | right-to-left | … = … |
… += … | |||
… -= … | |||
… **= … | |||
… *= … | |||
… /= … | |||
… %= … | |||
… <<= … | |||
… >>= … | |||
… >>>= … | |||
… &= … | |||
… ^= … | |||
… |= … | |||
… &&= … | |||
… ||= … | |||
… ??= … | |||
2 | yield | right-to-left | yield … |
yield* | yield* … | ||
1 | Comma / Sequence | left-to-right | … , … |
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
Operator precedence - JavaScript | MDN
Operator precedence determines how operators are parsed concerning each other. Operators with higher precedence become the operands of operators with lower precedence. The source for this interactive example is stored in a GitHub repository. If you'd like
developer.mozilla.org