9609c04755
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>
162 lines
5.5 KiB
Markdown
162 lines
5.5 KiB
Markdown
---
|
|
id: javascript-assignment
|
|
title: "JavaScript Assignment"
|
|
category: "Frontend"
|
|
status: "draft"
|
|
verification_status: "conceptual"
|
|
canonical_id: ""
|
|
aliases: ["JS assignment operators", "compound assignment", "logical assignment", "falsy values", "truthy values", "nullish coalescing assignment", "spread operator"]
|
|
duplicate_of: ""
|
|
source_trust_level: "B"
|
|
confidence_score: 0.87
|
|
created_at: 2026-06-23
|
|
updated_at: 2026-06-23
|
|
review_reason: ""
|
|
merge_history: []
|
|
tags: ["javascript", "js", "web", "frontend", "w3schools", "assignment", "operators"]
|
|
raw_sources: ["https://www.w3schools.com/js/js_assignment.asp"]
|
|
applied_in: []
|
|
github_commit: ""
|
|
---
|
|
|
|
# [[JavaScript Assignment]]
|
|
|
|
## 🎯 한 줄 통찰 (One-line insight)
|
|
Assignment operators assign values to variables — `=` for a plain assignment and compound forms (`+=`, `-=`, `*=`, `**=`, `/=`, `%=`) plus logical forms (`&&=`, `||=`, `??=`) for assign-and-operate in one step. [S1]
|
|
|
|
## 🧠 핵심 개념 (Core concepts)
|
|
- **Assignment operators assign values** — they assign values to JavaScript variables. [S1]
|
|
- **Compound assignment** — arithmetic compound operators combine an operation with assignment, e.g. `x += y` is the same as `x = x + y`. [S1]
|
|
- **Logical assignment** — `&&=`, `||=`, and `??=` assign conditionally based on truthiness/falsiness/nullishness. [S1]
|
|
- **8 falsy values** — `false`, `0`, `-0`, `0n`, `""` (empty strings), `null`, `undefined`, and `NaN` are falsy. [S1]
|
|
- **Truthy surprises** — `"0"`, `"false"`, `[]`, and `{}` are truthy even though they look "empty". [S1]
|
|
- **Spread `...`** — the `...` operator splits iterables into individual elements. [S1]
|
|
|
|
## 🧩 추출된 패턴 (Extracted patterns)
|
|
- **Mutate in place** — apply an operation to a variable and store back with one compound operator (`x += 5`). [S1]
|
|
- **Conditional assignment** — `x ??= 10` assigns only when `x` is null/undefined; `x ||= 10` when falsy; `x &&= 10` when truthy. [S1]
|
|
- **Falsy check awareness** — remember `"0"` and `"false"` strings (and `[]`/`{}`) are truthy when writing conditions. [S1]
|
|
|
|
## 📖 세부 내용 (Details)
|
|
**JavaScript Assignment Operators** [S1]
|
|
Assignment operators assign values to JavaScript variables. Using `x = 10` and `y = 5` for the examples below, the result column shows the value after applying the operator:
|
|
|
|
| Operator | Example | Same As | Result |
|
|
|----------|---------|---------|--------|
|
|
| = | x = y | x = y | x = 5 |
|
|
| += | x += y | x = x + y | x = 15 |
|
|
| -= | x -= y | x = x - y | x = 5 |
|
|
| *= | x *= y | x = x * y | x = 50 |
|
|
| **= | x **= y | x = x ** y | x = 100000 |
|
|
| /= | x /= y | x = x / y | x = 2 |
|
|
| %= | x %= y | x = x % y | x = 0 |
|
|
|
|
**The = Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
```
|
|
|
|
**The += Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x += 5;
|
|
```
|
|
|
|
**The -= Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x -= 5;
|
|
```
|
|
|
|
**The *= Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x *= 5;
|
|
```
|
|
|
|
**The **= Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x **= 5;
|
|
```
|
|
|
|
**The /= Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x /= 5;
|
|
```
|
|
|
|
**The %= Operator** [S1]
|
|
```javascript
|
|
let x = 10;
|
|
x %= 5;
|
|
```
|
|
|
|
**Logical Assignment Operators** [S1]
|
|
|
|
The `&&=` Operator (Logical AND assignment):
|
|
```javascript
|
|
let x = true;
|
|
let y = x &&= 10;
|
|
```
|
|
The `||=` Operator (Logical OR assignment):
|
|
```javascript
|
|
let x = false;
|
|
let y = x ||= 10;
|
|
```
|
|
The `??=` Operator (Nullish Coalescing assignment):
|
|
```javascript
|
|
let x;
|
|
x ??= 10;
|
|
```
|
|
|
|
**The 8 FALSY Values** [S1]
|
|
The following values are falsy: `false`, `0`, `-0`, `0n`, `""` / `''` / `` (empty strings), `null`, `undefined`, and `NaN`.
|
|
|
|
**These are TRUTHY** [S1]
|
|
The following values are truthy: `"0"` (string), `"false"` (string), `[]` (empty array), and `{}` (empty object).
|
|
|
|
**The Spread (...) Operator** [S1]
|
|
The `...` operator splits iterables into individual elements.
|
|
|
|
## 🛠️ 적용 사례 (Applied in summary)
|
|
The page's own snippets are the canonical applied examples — each compound operator demonstrated against `let x = 10`, and the logical-assignment operators shown against boolean/undefined seeds. No external project/commit applications found in the source.
|
|
|
|
## 💻 코드 패턴 (Code patterns)
|
|
Compound arithmetic assignment:
|
|
```javascript
|
|
let x = 10;
|
|
x += 5;
|
|
```
|
|
Nullish-coalescing assignment (only assigns when null/undefined):
|
|
```javascript
|
|
let x;
|
|
x ??= 10;
|
|
```
|
|
Logical OR assignment (assigns when falsy):
|
|
```javascript
|
|
let x = false;
|
|
let y = x ||= 10;
|
|
```
|
|
|
|
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
|
No contradictions found in the source. Worth noting: `"0"`, `"false"`, `[]`, and `{}` are truthy despite intuition, which the source explicitly flags.
|
|
|
|
## ✅ 검증 상태 및 신뢰도
|
|
- **상태:** draft
|
|
- **검증 단계:** conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
|
|
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
|
|
- **신뢰 점수:** 0.87
|
|
- **중복 검사 결과:** 신규 생성 (New discovery)
|
|
|
|
## 🔗 지식 그래프 (Knowledge Graph)
|
|
- **상위/루트:** [[JavaScript Tutorial]]
|
|
- **관련 개념:** [[JavaScript Operators]], [[JavaScript Arithmetic]], [[JavaScript Comparisons]], [[JavaScript Types]]
|
|
- **참조 맥락:** Referenced whenever updating a variable's value or doing conditional/defaulting assignment.
|
|
|
|
## 📚 출처 (Sources)
|
|
- [S1] W3Schools — JavaScript Assignment — https://www.w3schools.com/js/js_assignment.asp
|
|
|
|
## 📝 변경 이력 (Change history)
|
|
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Assignment" page (Astra wiki-curation, P-Reinforce v3.1 format).
|