|
4 | 4 |
|
5 | 5 | 자바스크립트에서 기본 수학 연산은 아래와 같은 문법을 사용해 표현할 수 있습니다. |
6 | 6 |
|
7 | | -<<<<<<< HEAD |
8 | 7 | - 보다 큼·작음: <code>a > b</code>, <code>a < b</code> |
9 | 8 | - 보다 크거나·작거나 같음: <code>a >= b</code>, <code>a <= b</code> |
10 | 9 | - 같음(동등): `a == b`. 등호 `=`가 두 개 연달아 오는 것에 유의하세요. `a = b`와 같이 등호가 하나일 때는 할당을 의미합니다. |
11 | | -- 같지 않음(부등): 같지 않음을 나타내는 수학 기호 <code>≠</code>는 자바스크립트에선 <code>a != b</code>로 나타냅니다. 할당연산자 `=` 앞에 느낌표 `!`를 붙여서 표시합니다. |
| 10 | +- 같지 않음(부등): 같지 않음을 나타내는 수학 기호 <code>≠</code>는 자바스크립트에선 <code>a != b</code>로 나타냅니다. |
12 | 11 |
|
13 | 12 | 이번 글에선 비교 시 일어나는 기이한 현상을 포함하여 다양한 자료형을 대상으로 자바스크립트가 어떻게 비교를 하는지에 대해 다룰 예정입니다. |
14 | 13 |
|
15 | 14 | 글 말미에는 자바스크립트에서만 일어나는 '기이한' 현상을 어떻게 예방할 수 있는지에 대해서 언급해두었습니다. |
16 | | -======= |
17 | | -- Greater/less than: <code>a > b</code>, <code>a < b</code>. |
18 | | -- Greater/less than or equals: <code>a >= b</code>, <code>a <= b</code>. |
19 | | -- Equals: `a == b`, please note the double equality sign `==` means the equality test, while a single one `a = b` means an assignment. |
20 | | -- Not equals: In maths the notation is <code>≠</code>, but in JavaScript it's written as <code>a != b</code>. |
21 | | - |
22 | | -In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities. |
23 | | - |
24 | | -At the end you'll find a good recipe to avoid "JavaScript quirks"-related issues. |
25 | | ->>>>>>> upstream/master |
26 | 15 |
|
27 | 16 | ## 불린형 반환 |
28 | 17 |
|
@@ -68,13 +57,9 @@ alert( 'Bee' > 'Be' ); // true |
68 | 57 | 4. 글자 간 비교가 끝날 때까지 이 과정을 반복합니다. |
69 | 58 | 5. 비교가 종료되었고 문자열의 길이도 같다면 두 문자열은 동일하다고 결론 냅니다. 비교가 종료되었지만 두 문자열의 길이가 다르면 길이가 긴 문자열이 더 크다고 결론 냅니다. |
70 | 59 |
|
71 | | -<<<<<<< HEAD |
72 | | -예시의 `'Z' > 'A'`는 위 알고리즘의 첫 번째 단계에서 비교 결과가 도출됩니다. 반면, 문자열 `'Glow'`와 `'Glee'`는 복수의 문자로 이루어진 문자열이기 때문에, 아래와 같은 순서로 문자열 비교가 이뤄집니다. |
73 | | -======= |
74 | | -In the first example above, the comparison `'Z' > 'A'` gets to a result at the first step. |
| 60 | +위 첫 번째 예시에서 `'Z' > 'A'` 비교는 첫 번째 단계에서 결과가 도출됩니다. |
75 | 61 |
|
76 | | -The second comparison `'Glow'` and `'Glee'` needs more steps as strings are compared character-by-character: |
77 | | ->>>>>>> upstream/master |
| 62 | +두 번째 비교인 `'Glow'`와 `'Glee'`는 문자열이 글자 단위로 비교되므로 더 많은 단계가 필요합니다. |
78 | 63 |
|
79 | 64 | 1. `G`는 `G`와 같습니다. |
80 | 65 | 2. `l`은 `l`과 같습니다. |
@@ -224,16 +209,8 @@ alert( undefined == 0 ); // false (3) |
224 | 209 |
|
225 | 210 | ## 요약 |
226 | 211 |
|
227 | | -<<<<<<< HEAD |
228 | 212 | - 비교 연산자는 불린값을 반환합니다. |
229 | 213 | - 문자열은 문자 단위로 비교되는데, 이때 비교 기준은 '사전' 순입니다. |
230 | 214 | - 서로 다른 타입의 값을 비교할 땐 숫자형으로 형 변환이 이뤄지고 난 후 비교가 진행됩니다(일치 연산자는 제외). |
231 | 215 | - `null`과 `undefined`는 동등 비교(`==`) 시 서로 같지만 다른 값과는 같지 않습니다. |
232 | | -- `null`이나 `undefined`가 될 확률이 있는 변수가 `>` 또는 `<`의 피연산자로 올 때는 주의를 기울이시기 바랍니다. `null`, `undefined` 여부를 확인하는 코드를 따로 추가하는 습관을 들이길 권유합니다. |
233 | | -======= |
234 | | -- Comparison operators return a boolean value. |
235 | | -- Strings are compared letter-by-letter in the "dictionary" order. |
236 | | -- When values of different types are compared, they get converted to numbers (with the exclusion of a strict equality check). |
237 | | -- The values `null` and `undefined` are equal `==` to themselves and each other, but do not equal any other value. |
238 | | -- Be careful when using comparisons like `>` or `<` with variables that can occasionally be `null/undefined`. Checking for `null/undefined` separately is a good idea. |
239 | | ->>>>>>> upstream/master |
| 216 | +- `null`이나 `undefined`가 될 확률이 있는 변수가 `>` 또는 `<`의 피연산자로 올 때는 주의를 기울이시기 바랍니다. `null`, `undefined` 여부를 확인하는 코드를 따로 추가하는 습관을 들이길 권유합니다. |
0 commit comments