Skip to content

Commit 9cd806b

Browse files
committed
[문서] C02 - 2.8 기본 연산자와 수학 충돌 해결 및 번역 진행
1 parent a57efba commit 9cd806b

3 files changed

Lines changed: 23 additions & 103 deletions

File tree

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,10 @@ undefined + 1 = NaN // (6)
1616
" \t \n" - 2 = -2 // (7)
1717
```
1818

19-
<<<<<<< HEAD
20-
1. 피 연산자 중 하나가 문자열인 `"" + 1`에서 `1`은 문자형으로 변환됩니다. 따라서 공백과 문자열 1을 더한, `"" + 1 = "1"`과 같은 효과를 발휘하죠. 그다음 연산 `"1" + 0`에도 같은 규칙이 적용됩니다.
19+
1. 피연산자 중 하나가 문자열인 `"" + 1`에서 `1`은 문자형으로 변환됩니다. 따라서 공백과 문자열 1을 더한, `"" + 1 = "1"`과 같은 효과를 발휘하죠. 그다음 연산 `"1" + 0`에도 같은 규칙이 적용됩니다.
2120
2. 뺄셈 연산자 `-`는 기타 수학 연산자처럼 숫자형만을 인수로 받습니다. 빈 문자열 `""`는 숫자 `0`으로 변환되기 때문에 결과는 `-1`이 됩니다.
22-
3. 피 연산자 중 하나가 문자열이므로 숫자 5가 문자열로 변환됩니다.
21+
3. 피연산자 중 하나가 문자열이므로 숫자 5가 문자열로 변환됩니다.
2322
4. 뺄셈 연산자는 인수를 숫자형으로 변화시키므로 `" -9 "`는 숫자 `-9`로 변합니다. 앞, 뒤 공백은 제거되죠.
2423
5. 숫자형으로 변환 시 `null``0`이 됩니다.
25-
6. `undefined`는 숫자형으로 변환시 `NaN`이 됩니다.
26-
7. 문자열이 숫자형으로 변할 땐 문자열 앞뒤의 공백이 삭제됩니다. 뺄셈 연산자 앞의 피연산자는 공백을 만드는 문자 `\t``\n`, 그 사이의 "일반적인" 공백으로 구성됩니다. 따라서 `" \t \n"`는 숫자형으로 변환 시 길이가 `0`인 문자열로 취급되어 숫자 `0`이 됩니다.
27-
=======
28-
1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
29-
2. The subtraction `-` (like most math operations) only works with numbers, it converts an empty string `""` to `0`.
30-
3. The addition with a string appends the number `5` to the string.
31-
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
32-
5. `null` becomes `0` after the numeric conversion.
33-
6. `undefined` becomes `NaN` after the numeric conversion.
34-
7. Space characters are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.
35-
>>>>>>> upstream/master
24+
6. `undefined`는 숫자형으로 변환 시 `NaN`이 됩니다.
25+
7. 문자열이 숫자형으로 변할 땐 문자열 앞뒤의 공백이 삭제됩니다. 뺄셈 연산자 앞의 피연산자는 공백을 만드는 문자 `\t``\n`, 그 사이의 "일반적인" 공백으로 구성됩니다. 따라서 `" \t \n"`는 숫자형으로 변환 시 길이가 `0`인 문자열로 취급되어 숫자 `0`이 됩니다.

1-js/02-first-steps/08-operators/4-fix-prompt/solution.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ let b = "2"; // prompt("덧셈할 두 번째 숫자를 입력해주세요.", 2);
99
alert(a + b); // 12
1010
```
1111

12-
<<<<<<< HEAD
1312
예시가 제대로 동작하게 하려면 덧셈 연산 `+`가 수행되기 전에 문자열을 숫자로 변환해야 합니다. 이때 `Number()`를 사용하거나 변수 앞에 `+`를 붙여줄 수 있습니다.
14-
=======
15-
What we should do is to convert strings to numbers before `+`. For example, using `Number()` or prepending them with `+`.
16-
>>>>>>> upstream/master
1713

1814
아래 코드에선 `prompt` 함수 바로 앞에서 문자열을 숫자로 변환했습니다.
1915

1-js/02-first-steps/08-operators/article.md

Lines changed: 19 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -50,46 +50,28 @@
5050
예시:
5151

5252
```js run
53-
<<<<<<< HEAD
5453
alert( 5 % 2 ); // 5를 2로 나눈 후의 나머지인 1을 출력
5554
alert( 8 % 3 ); // 8을 3으로 나눈 후의 나머지인 2를 출력
56-
=======
57-
alert( 5 % 2 ); // 1, the remainder of 5 divided by 2
58-
alert( 8 % 3 ); // 2, the remainder of 8 divided by 3
59-
alert( 8 % 4 ); // 0, the remainder of 8 divided by 4
60-
>>>>>>> upstream/master
55+
alert( 8 % 4 ); // 8을 4으로 나눈 후의 나머지인 0를 출력
6156
```
6257

6358
## 거듭제곱 연산자 **
6459

65-
<<<<<<< HEAD
6660
거듭제곱 연산자(exponentiation operator)를 사용한 `a ** b`를 평가하면 `a``b`번 곱한 값이 반환됩니다.
67-
=======
68-
The exponentiation operator `a ** b` raises `a` to the power of `b`.
6961

70-
In school maths, we write that as a<sup>b</sup>.
71-
>>>>>>> upstream/master
62+
학교 수학에선 이를 a<sup>b</sup>로 표기합니다.
7263

7364
예시:
7465

7566
```js run
76-
<<<<<<< HEAD
77-
alert( 2 ** 2 ); // 4 (2 * 2)
78-
alert( 2 ** 3 ); // 8 (2 * 2 * 2)
79-
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2)
80-
```
81-
82-
거듭제곱 연산자는 정수가 아닌 숫자에 대해서도 동작합니다. `1/2`을 사용하면 제곱근을 구할 수 있죠.
83-
=======
8467
alert( 2 ** 2 ); // 2² = 4
8568
alert( 2 ** 3 ); // 2³ = 8
8669
alert( 2 ** 4 ); // 2⁴ = 16
8770
```
8871

89-
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72+
수학에서와 마찬가지로, 거듭제곱 연산자는 정수가 아닌 숫자에 대해서도 동작합니다.
9073

91-
For example, a square root is an exponentiation by ½:
92-
>>>>>>> upstream/master
74+
예를 들어, 제곱근은 ½ 제곱으로 나타낼 수 있습니다.
9375

9476
```js run
9577
alert( 4 ** (1/2) ); // 2 (1/2 거듭제곱은 제곱근)
@@ -99,11 +81,7 @@ alert( 8 ** (1/3) ); // 2 (1/3 거듭제곱은 세제곱근)
9981

10082
## 이항 연산자 '+'와 문자열 연결
10183

102-
<<<<<<< HEAD
10384
이제 학교에서 배운 기본 산술 연산자를 넘어, 자바스크립트가 제공하는 특별한 연산자 기능에 대해 살펴봅시다.
104-
=======
105-
Let's meet the features of JavaScript operators that are beyond school arithmetics.
106-
>>>>>>> upstream/master
10785

10886
덧셈 연산자 `+`는 대개 숫자를 더한 결과를 반환합니다.
10987

@@ -131,16 +109,12 @@ alert( 2 + '1' ); // "21"
131109
alert(2 + 2 + '1' ); // '221'이 아니라 '41'이 출력됩니다.
132110
```
133111

134-
<<<<<<< HEAD
135-
연산은 왼쪽에서 오른쪽으로 순차적으로 진행되기 때문에 이런 결과가 나왔습니다. 두 개의 숫자 뒤에 문자열이 오는 경우, 숫자가 먼저 더해지고, 그 후 더해진 숫자와 문자열과의 병합이 일어납니다.
136-
=======
137-
Here, operators work one after another. The first `+` sums two numbers, so it returns `4`, then the next `+` adds the string `1` to it, so it's like `4 + '1' = '41'`.
112+
여기서는 연산자가 하나씩 순서대로 동작합니다. 첫 번째 `+`는 두 숫자를 더하므로 `4`를 반환하고, 그다음 `+`는 여기에 문자열 `'1'`을 더하므로 `4 + '1' = '41'`과 같은 결과가 됩니다.
138113

139114
```js run
140-
alert('1' + 2 + 2); // "122" and not "14"
115+
alert('1' + 2 + 2); // "14"가 아니라 "122"가 출력됩니다.
141116
```
142-
Here, the first operand is a string, the compiler treats the other two operands as strings too. The `2` gets concatenated to `'1'`, so it's like `'1' + 2 = "12"` and `"12" + 2 = "122"`.
143-
>>>>>>> upstream/master
117+
첫 번째 피연산자가 문자열이므로, 컴파일러는 나머지 두 피연산자도 문자열로 취급합니다. 2'1'에 병합되므로, '1' + 2 = "12"가 되고 "12" + 2 = "122"가 됩니다.
144118

145119
이처럼 이항 덧셈 연산자 `+`는 문자열 연결과 변환이라는 특별한 기능을 제공합니다. 다른 산술 연산자가 오직 숫자형의 피연산자만 다루고, 피연산자가 숫자형이 아닌 경우에 그 형을 숫자형으로 바꾸는 것과는 대조적입니다.
146120

@@ -216,51 +190,27 @@ alert( +apples + +oranges ); // 5
216190

217191
자바스크립트는 다양한 연산자를 제공하는데, 이 모든 연산자엔 우선순위가 매겨져 있습니다. 우선순위 숫자가 클수록 먼저 실행됩니다. 순위가 같으면 왼쪽부터 시작해서 오른쪽으로 연산이 수행됩니다.
218192

219-
<<<<<<< HEAD
220193
아래는 [우선순위 테이블(precedence table)](https://developer.mozilla.org/en/JavaScript/Reference/operators/operator_precedence)의 일부를 발췌한 표입니다. 순서를 기억할 필요는 없지만, 동일한 기호의 단항 연산자는 이항 연산자보다 우선순위가 더 높다는 것에 주목해 주시기 바랍니다.
221194

222195
| 순위 | 연산자 이름 | 기호 |
223196
| --- | ------ | --- |
224197
| ... | ... | ... |
225-
| 17 | 단항 덧셈 | `+` |
226-
| 17 | 단항 부정 | `-` |
227-
| 16 | 지수 | `**` |
228-
| 15 | 곱셈 | `*` |
229-
| 15 | 나눗셈 | `/` |
230-
| 13 | 덧셈 | `+` |
231-
| 13 | 뺄셈 | `-` |
198+
| 14 | 단항 덧셈 | `+` |
199+
| 14 | 단항 부정 | `-` |
200+
| 13 | 거듭제곱 | `**` |
201+
| 12 | 곱셈 | `*` |
202+
| 12 | 나눗셈 | `/` |
203+
| 11 | 덧셈 | `+` |
204+
| 11 | 뺄셈 | `-` |
232205
| ... | ... | ... |
233-
| 3 | 할당 | `=` |
206+
| 2 | 할당 | `=` |
234207
| ... | ... | ... |
235208

236-
'단항 덧셈 연산자'는 우선순위 `17`로, '(이항) 덧셈 연산자'의 우선순위 `13`보다 높습니다. 표현식 `"+apples + +oranges"`에서 단항 덧셈 연산자가 덧셈보다 먼저 수행되는 이유가 바로 이 때문입니다.
237-
=======
238-
Here's an extract from the [precedence table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence) (you don't need to remember this, but note that unary operators are higher than corresponding binary ones):
239-
240-
| Precedence | Name | Sign |
241-
|------------|------|------|
242-
| ... | ... | ... |
243-
| 14 | unary plus | `+` |
244-
| 14 | unary negation | `-` |
245-
| 13 | exponentiation | `**` |
246-
| 12 | multiplication | `*` |
247-
| 12 | division | `/` |
248-
| 11 | addition | `+` |
249-
| 11 | subtraction | `-` |
250-
| ... | ... | ... |
251-
| 2 | assignment | `=` |
252-
| ... | ... | ... |
253-
254-
As we can see, the "unary plus" has a priority of `14` which is higher than the `11` of "addition" (binary plus). That's why, in the expression `"+apples + +oranges"`, unary pluses work before the addition.
255-
>>>>>>> upstream/master
209+
'단항 덧셈 연산자'는 우선순위 `14`로, '(이항) 덧셈 연산자'의 우선순위 `11`보다 높습니다. 표현식 `"+apples + +oranges"`에서 단항 덧셈 연산자가 덧셈보다 먼저 수행되는 이유가 바로 이 때문입니다.
256210

257211
## 할당 연산자
258212

259-
<<<<<<< HEAD
260-
무언가를 할당할 때 쓰이는 `=`도 연산자입니다. 이 연산자는 할당(assignment) 연산자라고 불리는데, 우선순위는 `3`으로 아주 낮습니다.
261-
=======
262-
Let's note that an assignment `=` is also an operator. It is listed in the precedence table with the very low priority of `2`.
263-
>>>>>>> upstream/master
213+
무언가를 할당할 때 쓰이는 `=`도 연산자입니다. 이 연산자는 할당(assignment) 연산자라고 불리는데, 우선순위는 `2`으로 아주 낮습니다.
264214

265215
`x = 2 * 2 + 1`과 같은 표현식에서 계산이 먼저 이뤄지고, 그 결과가 `x`에 할당되는 이유가 바로 이 때문입니다.
266216

@@ -274,11 +224,7 @@ alert( x ); // 5
274224

275225
`=`는 연산자이기 때문에 흥미로운 함축성을 내포하고 있습니다.
276226

277-
<<<<<<< HEAD
278-
자바스크립트에서 대부분의 연산자들은 값을 반환합니다. `+``-`뿐만 아니라 `=` 역시 값을 반환하죠.
279-
=======
280-
All operators in JavaScript return a value. That's obvious for `+` and `-`, but also true for `=`.
281-
>>>>>>> upstream/master
227+
자바스크립트의 모든 연산자는 값을 반환합니다. `+``-`뿐만 아니라 `=` 역시 값을 반환하죠.
282228

283229
`x = value`을 호출하면 `value``x`에 쓰여지고, 이에 더하여 *`value`가 반환됩니다*.
284230

@@ -320,11 +266,7 @@ alert( c ); // 4
320266

321267
이렇게 할당 연산자를 여러 개 연결한 경우, 평가는 우측부터 진행됩니다. 먼저 가장 우측의 `2 + 2`가 평가되고, 그 결과가 좌측의 `c`, `b`, `a`에 순차적으로 할당됩니다. 모든 변수가 단일 값을 공유하게 되죠.
322268

323-
<<<<<<< HEAD
324269
그런데 되도록이면 연산자를 체이닝 하는것 보다 가독성을 위해 아래와 같이 줄을 나눠 코드를 작성하길 권유드립니다.
325-
=======
326-
Once again, for the purposes of readability it's better to split such code into a few lines:
327-
>>>>>>> upstream/master
328270

329271
```js
330272
c = 2 + 2;
@@ -364,11 +306,7 @@ let n = 2;
364306
365307
n *= 3 + 5; // right part evaluated first, same as n *= 8
366308
367-
<<<<<<< HEAD
368-
alert( n ); // 16 (*=의 우측이 먼저 평가되므로, 위 식은 n *= 8과 동일합니다.)
369-
=======
370309
alert( n ); // 16
371-
>>>>>>> upstream/master
372310
```
373311

374312
## 증가·감소 연산자
@@ -500,11 +438,7 @@ counter++;
500438
- 오른쪽 시프트(RIGHT SHIFT) ( `>>` )
501439
- 부호 없는 오른쪽 시프트(ZERO-FILL RIGHT SHIFT) ( `>>>` )
502440
503-
<<<<<<< HEAD
504-
비트 연산자는 저수준(2진 표현)에서 숫자를 다뤄야 할 때 쓰이므로 흔하게 쓰이진 않습니다. 웹 개발 시엔 이런 일이 자주 일어나지 않기 때문에 비트 연산자를 만날 일은 거의 없죠. 그렇긴 해도 암호를 다뤄야 할 땐 비트 연산자가 유용하기 때문에 때가 되면 MDN의 [비트 연산자](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) 문서를 보시는 걸 추천합니다.
505-
=======
506-
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises.
507-
>>>>>>> upstream/master
441+
비트 연산자는 저수준(2진 표현)에서 숫자를 다뤄야 할 때 쓰이므로 흔하게 쓰이진 않습니다. 웹 개발 시엔 이런 일이 자주 일어나지 않기 때문에 비트 연산자를 만날 일은 거의 없죠. 그렇긴 해도 암호를 다뤄야 할 땐 비트 연산자가 유용하기 때문에 때가 되면 MDN의 [비트 연산자](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) 문서를 보시는 걸 추천합니다.
508442
509443
## 쉼표 연산자
510444

0 commit comments

Comments
 (0)