aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/errors/bad_radix/index.html
blob: 15db6a1c7cdd21bd25df849a56254dae535e907d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: 'RangeError: radix must be an integer'
slug: Web/JavaScript/Reference/Errors/Bad_radix
tags:
- Error
- Errors
- JavaScript
- RangeError
translation_of: Web/JavaScript/Reference/Errors/Bad_radix
---
<div>{{jsSidebar("Errors")}}</div>

<p>JavaScript 예외 "radix must be an integer at least 2 and no greater than 36"는
    {{jsxref("Number.prototype.toString()")}} 또는 {{jsxref("BigInt.prototype.toString()")}}
    메서드의 선택적 매개 변수가 지정된 경우 2에서 36 사이여야 합니다.
</p>

<h2 id="Message">메시지</h2>

<pre class="brush: js">RangeError: invalid argument (Edge)
    RangeError: radix must be an integer at least 2 and no greater than 36 (Firefox)
    RangeError: toString() radix argument must be between 2 and 36 (Chrome)
    </pre>

<h2 id="Error_type">에러 형식</h2>

<p>{{jsxref("RangeError")}}</p>

<h2 id="What_went_wrong">무엇이 잘못되었을까?</h2>

<p>{{jsxref("Number.prototype.toString()")}} 또는 
    {{jsxref("BigInt.prototype.toString()")}} 
    메서드는 선택적 파라미터인 <code>radix</code>(기수: 진수를 지정하는 값)와 함게 사용되어 왔습니다.
    이 파라미터는 반드시 수의 값을 나타내는 진법 2와 36 사이로 지정된 정수(숫자)여야 합니다.
</p>

<p>
    이 매개 변수의 값이 36으로 제한된 이유는 무엇일까요?
    10보다 큰 기수는 알파벳 문자를 숫자로 사용하기 때문입니다.
    따라서 기수는 36을 초과할 수 없습니다. 라틴 알파벳(영어와 다른 많은 언어에서 사용됨)은 26자뿐이기 때문입니다.
</p>

<p>보통 아래의 <code>radix</code> 중 하나를 사용하게 될 것입니다.</p>

<ul>
 <li>2 for <a href="https://en.wikipedia.org/wiki/Binary_number">binary numbers</a> (2진수),</li>
 <li>8 for <a href="https://en.wikipedia.org/wiki/Octal">octal numbers</a> (8진수),</li>
 <li>10 for <a href="https://en.wikipedia.org/wiki/Decimal">decimal numbers</a> (10진수),</li>
 <li>16 for <a href="https://en.wikipedia.org/wiki/Hexadecimal">hexadecimal numbers</a> (16진수).</li>
</ul>

<h2 id="Examples">예제</h2>

<h3 id="Invalid_cases">허용되지 않는 경우</h3>

<pre class="brush: js example-bad">(42).toString(0);
(42).toString(1);
(42).toString(37);
(42).toString(150);
//포맷팅하기 위해 string을 이런 식으로 사용할 수는 없습니다. :
(12071989).toString("MM-dd-yyyy");
</pre>

<h3 id="Valid_cases">허용된 경우</h3>

<pre class="brush: js example-good">(42).toString(2);     // "101010" (2진수)
(13).toString(8);     // "15"     (8진수)
(0x42).toString(10);  // "66"     (10진수)
(100000).toString(16) // "186a0"  (16진수)
</pre>

<h2 id="See_also">또 다른 내용</h2>

<ul>
  <li>{{jsxref("Number.prototype.toString()")}}</li>
  <li>{{jsxref("BigInt.prototype.toString()")}}</li>
</ul>