You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`NaN`은 여간해선 바뀌지 않습니다. `NaN`에 어떤 추가 연산을 해도 결국 `NaN`이 반환됩니다.
51
-
52
-
```js run
53
-
alert( "숫자가 아님" / 2 + 5 ); // NaN
54
-
```
55
-
56
-
연산 과정 어디에선가 `NaN`이 반환되었다면, 이는 모든 결과에 영향을 미칩니다.
57
-
=======
58
-
`NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`:
49
+
`NaN`은 여간해선 바뀌지 않습니다. `NaN`에 어떤 추가 수학 연산을 해도 결국 `NaN`이 반환됩니다.
59
50
60
51
```js run
61
52
alert( NaN + 1 ); // NaN
62
53
alert( 3 * NaN ); // NaN
63
-
alert( "not a number" / 2 - 1 ); // NaN
54
+
alert( "숫자가 아님" / 2 - 1 ); // NaN
64
55
```
65
56
66
-
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that:`NaN ** 0` is `1`).
67
-
>>>>>>> upstream/master
57
+
연산 과정 어디에선가 `NaN`이 반환되었다면, 이는 모든 결과에 영향을 미칩니다. (단 하나의 예외는 `NaN ** 0`이 `1`이 된다는 점입니다.)
68
58
69
59
```smart header="수학 연산은 안전합니다."
70
60
자바스크립트에서 행해지는 수학 연산은 '안전'하다고 볼 수 있습니다. 0으로 나눈다거나 숫자가 아닌 문자열을 숫자로 취급하는 등의 이례적인 연산이 자바스크립트에선 가능합니다.
@@ -78,26 +68,20 @@ n = 12.345;
78
68
79
69
## BigInt [#bigint-type]
80
70
81
-
<<<<<<<HEAD
82
-
내부 표현 방식 때문에 자바스크립트에선 <code>(2<sup>53</sup>-1)</code>(`9007199254740991`) 보다 큰 값 혹은 <code>-(2<sup>53</sup>-1)</code> 보다 작은 정수는 '숫자형'을 사용해 나타낼 수 없습니다.
71
+
내부 표현 방식 때문에 자바스크립트에선 <code>(2<sup>53</sup>-1)</code>(`9007199254740991`) 보다 큰 정수 혹은 <code>-(2<sup>53</sup>-1)</code> 보다 작은 정수는 '숫자형'을 사용해 나타낼 수 없습니다.
83
72
84
-
사실 대부분의 상황에서 이런 제약사항은 문제가 되지 않습니다. 그렇지만 암호 관련 작업같이 아주 큰 숫자가 필요한 상황이거나 아주 높은 정밀도로 작업을 해야 할 때는 이런 큰 숫자가 필요합니다.
85
-
=======
86
-
In JavaScript, the "number" type cannot safely represent integer values larger than <code>(2<sup>53</sup>-1)</code> (that's `9007199254740991`), or less than <code>-(2<sup>53</sup>-1)</code> for negatives.
87
-
88
-
To be really precise, the "number" type can store larger integers (up to <code>1.7976931348623157 * 10<sup>308</sup></code>), but outside of the safe integer range <code>±(2<sup>53</sup>-1)</code> there'll be a precision error, because not all digits fit into the fixed 64-bit storage. So an "approximate" value may be stored.
73
+
정확히 말하면, '숫자형'은 더 큰 정수도 저장할 수 있습니다. 최대 <code>1.7976931348623157*10<sup>308</sup></code>까지 저장할 수 있죠. 하지만 안전한 정수의 범위인 <code>±(2<sup>53</sup>-1)</code>를 벗어나면 정밀도 오류가 발생합니다. 모든 자릿수를 고정된 64비트 저장 공간에 담을 수 없기 때문입니다. 따라서 '근삿값'이 저장될 수 있습니다.
89
74
90
-
For example, these two numbers (right above the safe range) are the same:
So to say, all odd integers greater than <code>(2<sup>53</sup>-1)</code> can't be stored at all in the "number" type.
82
+
다시 말해, <code>(2<sup>53</sup>-1)</code>보다 큰 모든 홀수 정수는 '숫자형'에 아예 저장할 수 없습니다.
98
83
99
-
For most purposes <code>±(2<sup>53</sup>-1)</code> range is quite enough, but sometimes we need the entire range of really big integers, e.g. for cryptography or microsecond-precision timestamps.
100
-
>>>>>>> upstream/master
84
+
사실 대부분의 상황에서 이런 제약사항은 문제가 되지 않습니다. 그렇지만 암호 관련 작업같이 아주 큰 숫자가 필요한 상황이거나 아주 높은 정밀도로 작업을 해야 할 때는 이런 큰 숫자가 필요합니다.
101
85
102
86
`BigInt`형은 표준으로 채택된 지 얼마 안 된 자료형으로, 길이에 상관없이 정수를 나타낼 수 있습니다.
`BigInt`형 숫자는 자주 쓰이지 않기 때문에 여기서 자세히 다루지 않고 별도의 챕터, <info:bigint>에서 설명드리겠습니다. 아주 큰 숫자를 사용해야 하는 경우라면 해당 챕터를 참고해 주시기 바랍니다.
112
96
113
-
<<<<<<< HEAD
114
-
```smart header="호환성 이슈"
115
-
이 글이 작성된 시점엔 Firefox, Chrome, Edge, Safari에서만 `BigInt`를 지원합니다. IE에선 지원하지 않습니다.
116
-
```
117
-
118
97
## 문자형
119
-
=======
120
-
## String
121
-
>>>>>>> upstream/master
122
98
123
99
자바스크립트에선 문자열(string)을 따옴표로 묶습니다.
124
100
@@ -160,11 +136,7 @@ alert( "the result is ${1 + 2}" ); // the result is ${1 + 2} (큰따옴표는
160
136
```smart header="*글자형*은 없습니다."
161
137
일부 언어는 글자 하나를 저장할 때 쓰이는 자료형, '글자(character)'형을 따로 지원합니다. C 언어와 Java의 `char`가 대표적인 예입니다.
162
138
163
-
<<<<<<< HEAD
164
-
자바스크립트는 글자형을 지원하지 않습니다. `문자형`만 있을 뿐입니다. 여기엔 글자가 하나 혹은 여러 개 들어갈 수 있습니다.
165
-
=======
166
-
In JavaScript, there is no such type. There's only one type:`string`. A string may consist of zero characters (be empty), one character or many of them.
167
-
>>>>>>> upstream/master
139
+
자바스크립트는 글자형을 지원하지 않습니다. `문자형`만 있을 뿐입니다. 여기엔 글자가 0개일 수도 있고(빈 문자열), 하나 혹은 여러 개일 수도 있습니다.
168
140
```
169
141
170
142
## 불린형
@@ -245,22 +217,9 @@ alert(age); // "undefined"
245
217
246
218
## typeof 연산자 [#type-typeof]
247
219
248
-
<<<<<<< HEAD
249
220
`typeof` 연산자는 인수의 자료형을 반환합니다. 자료형에 따라 처리 방식을 다르게 하고 싶거나 변수의 자료형을 빠르게 알아내고자 할 때 유용합니다.
250
221
251
-
`typeof` 연산자는 두 가지 형태의 문법을 지원합니다.
252
-
253
-
1. 연산자: `typeof x`
254
-
2. 함수: `typeof(x)`
255
-
256
-
괄호가 있든 없든 결과가 동일합니다.
257
-
258
222
`typeof x`를 호출하면 인수의 자료형을 나타내는 문자열을 반환합니다.
259
-
=======
260
-
The `typeof` operator returns the type of the operand. It's useful when we want to process values of different types differently or just want to do a quick check.
261
-
262
-
A call to `typeof x` returns a string with the type name:
1.`Math`는 수학 연산을 제공하는 내장 객체이므로 `"object"`가 출력됩니다. `Math`에 대해선 <info:number> 챕터에서 학습하도록 하겠습니다. 내장 객체는 객체형이라는 것을 알려주기 위해 이런 예시를 작성해 보았습니다.
295
253
2.`typeof null`의 결과는 `"object"`입니다. `null`은 별도의 고유한 자료형을 가지는 특수 값으로 객체가 아니지만, 하위 호환성을 유지하기 위해 이런 오류를 수정하지 않고 남겨둔 상황입니다. 언어 자체의 오류이므로 `null`이 객체가 아님에 유의하시기 바랍니다.
296
254
3.`typeof`는 피연산자가 함수면 `"function"`을 반환합니다. 그러므로 `typeof alert`는 `"function"`을 출력해줍니다. 그런데 '함수'형은 따로 없습니다. 함수는 객체형에 속합니다. 이런 동작 방식이 형식적으론 잘못되긴 했지만, 아주 오래전에 만들어진 규칙이었기 때문에 하위 호환성 유지를 위해 남겨진 상태입니다. 한편, 실무에선 이런 특징이 매우 유용하게 사용되기도 합니다.
297
255
298
-
## 요약
299
-
=======
300
-
1. `Math` is a built-in object that provides mathematical operations. We will learn it in the chapter <info:number>. Here, it serves just as an example of an object.
301
-
2. The result of `typeofnull` is `"object"`. That's an officially recognized error in `typeof`, coming from very early days of JavaScript and kept for compatibility. Definitely, `null` is not an object. It is a special value with a separate type of its own. The behavior of `typeof` is wrong here.
302
-
3. The result of `typeof alert` is `"function"`, because `alert` is a function. We'll study functions in the next chapters where we'll also see that there's no special "function" type in JavaScript. Functions belong to the object type. But `typeof` treats them differently, returning `"function"`. That also comes from the early days of JavaScript. Technically, such behavior isn't correct, but can be convenient in practice.
303
-
304
-
```smart header="The `typeof(x)` syntax"
305
-
You may also come across another syntax:`typeof(x)`. It's the same as `typeof x`.
256
+
```smart header="`typeof(x)` 문법"
257
+
코드에서 `typeof(x)`라는 또 다른 문법을 보실 수도 있습니다. 이는 `typeof x`와 동일합니다.
306
258
307
-
To put it clear: `typeof` is an operator, not a function. The parentheses here aren't a part of`typeof`. It's the kind of parentheses used for mathematical grouping.
259
+
정확히 말하자면, `typeof`는 함수가 아니라 연산자입니다. 여기서 괄호는 `typeof`의 일부가 아닙니다. 수학에서 식을 묶을 때 쓰는 괄호와 같은 종류의 괄호입니다.
308
260
309
-
Usually, such parentheses contain a mathematical expression, such as `(2 + 2)`, but here they contain only one argument `(x)`. Syntactically, they allow to avoid a space between the `typeof` operator and its argument, and some people like it.
261
+
보통 이런 괄호 안에는 `(2 + 2)`처럼 수식이 들어가지만, 여기서는 `(x)`처럼 인수 하나만 들어갑니다. 문법적으로는 `typeof`연산자와 인수 사이에 공백을 쓰지 않게 해주며, 이를 선호하는 사람들도 있습니다.
310
262
311
-
Some people prefer `typeof(x)`, although the `typeof x` syntax is much more common.
263
+
`typeof x` 문법이 훨씬 더 일반적이지만, `typeof(x)`를 선호하는 사람들도 있습니다.
312
264
```
313
265
314
-
## Summary
315
-
>>>>>>> upstream/master
266
+
## 요약
316
267
317
268
자바스크립트에는 여덟 가지 기본 자료형이 있습니다.
318
269
319
-
<<<<<<< HEAD
320
-
- `숫자형` -- 정수, 부동 소수점 숫자 등의 숫자를 나타낼 때 사용합니다. 정수의 한계는 ±2<sup>53</sup> 입니다.
321
-
- `bigint` -- 길이 제약 없이 정수를 나타낼 수 있습니다.
322
-
- `문자형` -- 빈 문자열이나 글자들로 이뤄진 문자열을 나타낼 때 사용합니다. 단일 문자를 나타내는 별도의 자료형은 없습니다.
323
-
- `불린형` -- `true`, `false`를 나타낼 때 사용합니다.
324
-
- `null` -- `null` 값만을 위한 독립 자료형입니다. `null`은 알 수 없는 값을 나타냅니다.
325
-
- `undefined` -- `undefined` 값만을 위한 독립 자료형입니다. `undefined`는 할당되지 않은 값을 나타냅니다.
326
-
- `객체형` -- 복잡한 데이터 구조를 표현할 때 사용합니다.
327
-
- `심볼형` -- 객체의 고유 식별자를 만들 때 사용합니다.
328
-
=======
329
-
- Seven primitive data types:
330
-
- `number` for numbers of any kind: integer or floating-point, integers are limited by <code>±(2<sup>53</sup>-1)</code>.
331
-
- `bigint` for integer numbers of arbitrary length.
332
-
- `string` for strings. A string may have zero or more characters, there's no separate single-character type.
333
-
-`boolean`for`true`/`false`.
334
-
-`null`for unknown values -- a standalone type that has a single value `null`.
335
-
-`undefined`for unassigned values -- a standalone type that has a single value `undefined`.
336
-
-`symbol`for unique identifiers.
337
-
- And one non-primitive data type:
338
-
-`object`for more complex data structures.
339
-
>>>>>>> upstream/master
270
+
- 원시 자료형 일곱 가지는 다음과 같습니다.
271
+
- `숫자형` -- 정수, 부동 소수점 숫자 등의 숫자를 나타낼 때 사용합니다. 정수의 한계는 <code>±(2<sup>53</sup>-1)</code> 입니다.
272
+
- `bigint` -- 길이 제약 없이 정수를 나타낼 수 있습니다.
273
+
- `문자형` -- 빈 문자열이나 글자들로 이뤄진 문자열을 나타낼 때 사용합니다. 단일 문자를 나타내는 별도의 자료형은 없습니다.
274
+
- `불린형` -- `true`, `false`를 나타낼 때 사용합니다.
275
+
- `null` -- `null` 값만을 위한 독립 자료형입니다. `null`은 알 수 없는 값을 나타냅니다.
276
+
- `undefined` -- `undefined` 값만을 위한 독립 자료형입니다. `undefined`는 할당되지 않은 값을 나타냅니다.
277
+
- `심볼형` -- 객체의 고유 식별자를 만들 때 사용합니다.
278
+
- 그리고 원시 자료형이 아닌 자료형이 하나 있습니다.
279
+
- `객체형` -- 복잡한 데이터 구조를 표현할 때 사용합니다.
340
280
341
281
`typeof` 연산자는 피연산자의 자료형을 알려줍니다.
342
282
343
-
<<<<<<<HEAD
344
-
-`typeof x` 또는 `typeof(x)` 형태로 사용합니다.
283
+
- 보통 `typeof x` 형태로 사용하지만, `typeof(x)` 형태도 가능합니다.
345
284
- 피연산자의 자료형을 문자열 형태로 반환합니다.
346
-
-`null`의 typeof 연산은 `"object"`인데, 이는 언어상 오류입니다. null은 객체가 아닙니다.
347
-
=======
348
-
- Usually used as `typeof x`, but `typeof(x)` is also possible.
349
-
- Returns a string with the name of the type, like `"string"`.
350
-
- For `null` returns `"object"`--this is an error in the language, it's not actually an object.
0 commit comments