docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)

W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더).
- Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외)
- Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체)
- Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속)
각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-23 19:21:18 +09:00
parent 8957890d13
commit 9609c04755
379 changed files with 54618 additions and 6 deletions
@@ -0,0 +1,270 @@
---
id: javascript-numbers
title: "JavaScript Numbers"
category: "Frontend"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["numbers", "JS numbers", "floating point", "NaN", "Infinity", "IEEE 754"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.89
created_at: 2026-06-23
updated_at: 2026-06-23
review_reason: ""
merge_history: []
tags: ["javascript", "js", "web", "frontend", "w3schools", "numbers", "floating-point", "nan"]
raw_sources: ["https://www.w3schools.com/js/js_numbers.asp"]
applied_in: []
github_commit: ""
---
# [[JavaScript Numbers]]
## 🎯 한 줄 통찰 (One-line insight)
JavaScript has only one number type — a 64-bit IEEE 754 double — so integers are precise only to 15 digits, floating-point arithmetic can be imprecise, and special values `NaN` and `Infinity` are themselves of type `number`. [S1]
## 🧠 핵심 개념 (Core concepts)
- **One number type** — JavaScript has only one type of number; numbers can be written with or without decimals, and scientific notation (`123e5`) is allowed. [S1]
- **Always 64-bit floating point** — JavaScript numbers are always stored as double precision floating point following the IEEE 754 standard (fraction in bits 0-51, exponent in 52-62, sign in bit 63). [S1]
- **Integer precision** — integers are accurate up to 15 digits; the maximum number of decimals is 17. [S1]
- **Floating precision** — floating point arithmetic is not always 100% accurate (e.g. `0.2 + 0.1`). [S1]
- **`+` is addition AND concatenation** — numbers are added; strings are concatenated; mixing them concatenates left-to-right. [S1]
- **`NaN`** — a reserved word meaning "not a legal number"; `typeof NaN` returns `number`; use `isNaN()` to test. [S1]
- **`Infinity`** — returned when a value exceeds the largest possible number, or on division by 0; `typeof Infinity` returns `number`. [S1]
- **Hexadecimal** — constants prefixed with `0x` are interpreted as hexadecimal; `toString()` can output base 2 to base 36. [S1]
- **Numbers as objects** — `new Number()` creates an object; the page warns not to create Number objects. [S1]
## 🧩 추출된 패턴 (Extracted patterns)
- **Fix floating drift** — multiply and divide (`(0.2 * 10 + 0.1 * 10) / 10`) to work around floating-point imprecision. [S1]
- **Guard against NaN** — test inputs with `isNaN()` before using them in arithmetic, since `NaN` propagates through operations. [S1]
- **Force numeric addition** — beware that `"10" + 20` concatenates; ensure operands are numbers when you intend addition. [S1]
- **Base conversion** — use `number.toString(radix)` to render in binary, octal, hex, or any base 2-36. [S1]
## 📖 세부 내용 (Details)
**Number Types**
JavaScript has only one type of number. Numbers can be written with or without decimals. [S1]
```javascript
let x = 3.14; // A number with decimals
let y = 3; // A number without decimals
```
Extra large or extra small numbers can be written with scientific (exponent) notation: [S1]
```javascript
let x = 123e5; // 12300000
let y = 123e-5; // 0.00123
```
**JavaScript Numbers are Always 64-bit Floating Point**
Unlike many other languages, JavaScript does not define different number types (integers, short, long, float, etc.). Numbers are always stored as double precision floating point following IEEE 754, in 64 bits: the fraction in bits 0-51, the exponent in bits 52-62, and the sign in bit 63. [S1]
| Value (aka Fraction/Mantissa) | Exponent | Sign |
|---|---|---|
| 52 bits (0 - 51) | 11 bits (52 - 62) | 1 bit (63) |
JavaScript numbers are always double (64-bit floating point). [S1]
**Integer Precision**
Integers (numbers without a period or exponent notation) are accurate up to 15 digits. The maximum number of decimals is 17. [S1]
```javascript
let x = 999999999999999; // x will be 999999999999999
let y = 9999999999999999; // y will be 10000000000000000
```
**Floating Precision**
Floating point arithmetic is not always 100% accurate: [S1]
```javascript
let x = 0.2 + 0.1;
```
To solve the problem above, it helps to multiply and divide: [S1]
```javascript
let x = (0.2 * 10 + 0.1 * 10) / 10;
```
**Adding Numbers and Strings**
> Warning: JavaScript uses the `+` operator for both addition and concatenation. Numbers are added. Strings are concatenated. [S1]
Adding two numbers gives a number: [S1]
```javascript
let x = 10;
let y = 20;
let z = x + y;
```
Adding two strings gives a concatenation: [S1]
```javascript
let x = "10";
let y = "20";
let z = x + y;
```
Adding a number and a string gives a concatenation: [S1]
```javascript
let x = 10;
let y = "20";
let z = x + y;
```
Adding a string and a number gives a concatenation: [S1]
```javascript
let x = "10";
let y = 20;
let z = x + y;
```
A common mistake is to expect this to be 30: [S1]
```javascript
let x = 10;
let y = 20;
let z = "The result is: " + x + y;
```
A common mistake is to expect this to be 102030: [S1]
```javascript
let x = 10;
let y = 20;
let z = "30";
let result = x + y + z;
```
The JavaScript interpreter works from left to right. First `10 + 20` is added because `x` and `y` are both numbers; then `30 + "30"` is concatenated because `z` is a string. [S1]
**Numeric Strings**
JavaScript will try to convert strings to numbers in numeric operations. Division, multiplication, and subtraction work; addition concatenates. [S1]
```javascript
let x = "100";
let y = "10";
let z = x / y;
```
```javascript
let x = "100";
let y = "10";
let z = x * y;
```
```javascript
let x = "100";
let y = "10";
let z = x - y;
```
This will NOT work (it concatenates): [S1]
```javascript
let x = "100";
let y = "10";
let z = x + y;
```
**NaN - Not a Number**
`NaN` is a JavaScript reserved word indicating that a number is not a legal number. Arithmetic with a non-numeric string yields `NaN`: [S1]
```javascript
let x = 100 / "Apple";
```
If the string is numeric, the result is a number: [S1]
```javascript
let x = 100 / "10";
```
Use `isNaN()` to test: [S1]
```javascript
let x = 100 / "Apple";
isNaN(x);
```
`NaN` propagates through math: [S1]
```javascript
let x = NaN;
let y = 5;
let z = x + y;
```
Or it concatenates like `NaN5`: [S1]
```javascript
let x = NaN;
let y = "5";
let z = x + y;
```
`typeof NaN` returns `number`: [S1]
```javascript
typeof NaN;
```
**Infinity**
`Infinity` (or `-Infinity`) is returned for a number outside the largest possible number. [S1]
```javascript
let myNumber = 2;
// Execute until Infinity
while (myNumber != Infinity) {
myNumber = myNumber * myNumber;
}
```
Division by 0 also generates `Infinity`: [S1]
```javascript
let x = 2 / 0;
let y = -2 / 0;
```
`typeof Infinity` returns `number`: [S1]
```javascript
typeof Infinity;
```
**Hexadecimal**
JavaScript interprets numeric constants as hexadecimal if they are preceded by `0x`. [S1]
```javascript
let x = 0xFF;
```
Never write a number with a leading zero (like `07`); some versions interpret it as octal. By default JavaScript displays numbers as base 10, but `toString()` can output base 2 to base 36 (hex = base 16, decimal = base 10, octal = base 8, binary = base 2): [S1]
```javascript
let myNumber = 32;
myNumber.toString(32);
myNumber.toString(16);
myNumber.toString(12);
myNumber.toString(10);
myNumber.toString(8);
myNumber.toString(2);
```
**JavaScript Numbers as Objects**
Numbers are normally primitive values from literals, but can be defined as objects with `new`: [S1]
```javascript
let x = 123;
let y = new Number(123);
```
> Warning: Do not create Number objects. The `new` keyword complicates the code and slows down execution speed. [S1]
With `==`, a primitive and a Number object are equal; with `===` they are not equal; and comparing two Number objects always returns false: [S1]
```javascript
let x = 500;
let y = new Number(500);
```
```javascript
let x = new Number(500);
let y = new Number(500);
```
## 🛠️ 적용 사례 (Applied in summary)
The page's own snippets are the canonical applied examples — demonstrating integer precision limits, the `0.2 + 0.1` floating drift fix, `+` concatenation pitfalls, `isNaN()` checks, the `Infinity` loop, and `toString(radix)` base conversions. No external project/commit applications found in the source.
## 💻 코드 패턴 (Code patterns)
Work around floating drift:
```javascript
let x = (0.2 * 10 + 0.1 * 10) / 10;
```
Detect a non-number:
```javascript
isNaN(100 / "Apple");
```
Convert to another base:
```javascript
(32).toString(2); // binary
(32).toString(16); // hexadecimal
```
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
Note that `0.2 + 0.1` does not produce exactly `0.3` due to IEEE 754 floating point; the page presents the multiply/divide workaround. No contradictions found in the source.
## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.89
- **중복 검사 결과:** 신규 생성 (New discovery)
## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[JavaScript Tutorial]]
- **관련 개념:** [[JavaScript Number Methods]], [[JavaScript Data Types]], [[JavaScript Operators]], [[JavaScript BigInt]]
- **참조 맥락:** The foundation for all numeric computation and the precision pitfalls behind money/financial calculations.
## 📚 출처 (Sources)
- [S1] W3Schools — JavaScript Numbers — https://www.w3schools.com/js/js_numbers.asp
## 📝 변경 이력 (Change history)
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Numbers" page (Astra wiki-curation, P-Reinforce v3.1 format).