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>
212 lines
7.0 KiB
Markdown
212 lines
7.0 KiB
Markdown
---
|
|
id: javascript-destructuring
|
|
title: "JavaScript Destructuring"
|
|
category: "Frontend"
|
|
status: "draft"
|
|
verification_status: "conceptual"
|
|
canonical_id: ""
|
|
aliases: ["destructuring", "JS destructuring", "destructuring assignment", "object destructuring", "array destructuring", "rest property"]
|
|
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", "destructuring", "es6"]
|
|
raw_sources: ["https://www.w3schools.com/js/js_destructuring.asp"]
|
|
applied_in: []
|
|
github_commit: ""
|
|
---
|
|
|
|
# [[JavaScript Destructuring]]
|
|
|
|
## 🎯 한 줄 통찰 (One-line insight)
|
|
Destructuring assignment unpacks objects and arrays (and any iterable) into individual variables without mutating the original — supporting defaults, aliases, skipping, position picks, and a rest property. [S1]
|
|
|
|
## 🧠 핵심 개념 (Core concepts)
|
|
- **Unpacks objects into variables** — The destructuring assignment syntax can unpack objects into variables. [S1]
|
|
- **Order-independent for objects** — When destructuring objects, the order of the properties does not matter. [S1]
|
|
- **Non-destructive** — Destructuring is not destructive; it does not change the original object. [S1]
|
|
- **Default values** — For potentially missing properties you can set default values. [S1]
|
|
- **Property aliases** — A destructured property can be renamed into a different variable name. [S1]
|
|
- **Works on any iterable** — Destructuring can be used with any iterables, including strings. [S1]
|
|
- **Array picks and skips** — You can pick array variables, skip values with extra commas, and pick by specific index. [S1]
|
|
- **Rest property** — Ending a destructuring with a rest property stores all remaining values into a new array. [S1]
|
|
|
|
## 🧩 추출된 패턴 (Extracted patterns)
|
|
- **`{a, b} = obj`** — Object destructuring binds by property name, in any order. [S1]
|
|
- **`{x = default}`** — Supply defaults inline for properties that may be missing. [S1]
|
|
- **`{prop : alias}`** — Rename a property into a new variable. [S1]
|
|
- **`[a,,,b]`** — Use extra commas to skip array positions. [S1]
|
|
- **`{[0]:x ,[1]:y}`** — Pick array values by specific index. [S1]
|
|
- **`[a, b, ...rest]`** — Collect remaining array values into `rest`. [S1]
|
|
- **`[a, b] = [b, a]`** — Swap two variables in one statement. [S1]
|
|
|
|
## 📖 세부 내용 (Details)
|
|
**Destructuring Assignment Syntax**
|
|
The destructuring assignment syntax can unpack objects into variables: [S1]
|
|
```javascript
|
|
let {firstName, lastName} = person;
|
|
```
|
|
|
|
**Object Destructuring** [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
age: 50
|
|
};
|
|
|
|
// Destructuring
|
|
let {firstName, lastName} = person;
|
|
```
|
|
The order of the properties does not matter: [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
age: 50
|
|
};
|
|
|
|
// Destructuring
|
|
let {lastName, firstName} = person;
|
|
```
|
|
Destructuring is not destructive. Destructuring does not change the original object. [S1]
|
|
|
|
**Object Default Values** — For potentially missing properties we can set default values: [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
age: 50
|
|
};
|
|
|
|
// Destructuring
|
|
let {firstName, lastName, country = "US"} = person;
|
|
```
|
|
|
|
**Object Property Alias** [S1]
|
|
```javascript
|
|
// Create an Object
|
|
const person = {
|
|
firstName: "John",
|
|
lastName: "Doe",
|
|
age: 50
|
|
};
|
|
|
|
// Destructuring
|
|
let {lastName : name} = person;
|
|
```
|
|
|
|
**String Destructuring** — One use for destructuring is unpacking string characters. Destructuring can be used with any iterables. [S1]
|
|
```javascript
|
|
// Create a String
|
|
let name = "W3Schools";
|
|
|
|
// Destructuring
|
|
let [a1, a2, a3, a4, a5] = name;
|
|
```
|
|
|
|
**Array Destructuring** — We can pick up array variables into our own variables: [S1]
|
|
```javascript
|
|
// Create an Array
|
|
const fruits = ["Bananas", "Oranges", "Apples", "Mangos"];
|
|
|
|
// Destructuring
|
|
let [fruit1, fruit2] = fruits;
|
|
```
|
|
|
|
**Skipping Array Values** — We can skip array values using two or more commas: [S1]
|
|
```javascript
|
|
// Create an Array
|
|
const fruits = ["Bananas", "Oranges", "Apples", "Mangos"];
|
|
|
|
// Destructuring
|
|
let [fruit1,,,fruit2] = fruits;
|
|
```
|
|
|
|
**Array Position Values** — We can pick up values from specific index locations of an array: [S1]
|
|
```javascript
|
|
// Create an Array
|
|
const fruits = ["Bananas", "Oranges", "Apples", "Mangos"];
|
|
// Destructuring
|
|
let {[0]:fruit1 ,[1]:fruit2} = fruits;
|
|
```
|
|
|
|
**The Rest Property** — You can end a destructuring syntax with a rest property. This syntax will store all remaining values into a new array: [S1]
|
|
```javascript
|
|
// Create an Array
|
|
const numbers = [10, 20, 30, 40, 50, 60, 70];
|
|
|
|
// Destructuring
|
|
const [a,b, ...rest] = numbers
|
|
```
|
|
|
|
**Destructuring Maps** [S1]
|
|
```javascript
|
|
// Create a Map
|
|
const fruits = new Map([
|
|
["apples", 500],
|
|
["bananas", 300],
|
|
["oranges", 200]
|
|
]);
|
|
|
|
// Destructuring
|
|
let text = "";
|
|
for (const [key, value] of fruits) {
|
|
text += key + " is " + value;
|
|
}
|
|
```
|
|
|
|
**Swapping JavaScript Variables** — You can swap the values of two variables using a destructuring assignment: [S1]
|
|
```javascript
|
|
let firstName = "John";
|
|
let lastName = "Doe";
|
|
|
|
// Destructuring
|
|
[firstName, lastName] = [lastName, firstName];
|
|
```
|
|
|
|
## 🛠️ 적용 사례 (Applied in summary)
|
|
The page's own snippets are the canonical applied examples — object/array destructuring, defaults, aliases, string and Map iteration, the rest property, and the variable-swap idiom. No external project/commit applications found in the source.
|
|
|
|
## 💻 코드 패턴 (Code patterns)
|
|
Object destructuring with default and alias (language: JavaScript):
|
|
```javascript
|
|
let {firstName, lastName, country = "US"} = person;
|
|
let {lastName : name} = person;
|
|
```
|
|
Rest property collects the remainder:
|
|
```javascript
|
|
const [a, b, ...rest] = numbers;
|
|
```
|
|
Swap two variables:
|
|
```javascript
|
|
[firstName, lastName] = [lastName, firstName];
|
|
```
|
|
|
|
## ⚖️ 모순 및 업데이트 (Contradictions & updates)
|
|
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 Object Types Note]], [[JavaScript Type Conversion]], [[JavaScript Introduction]], [[JavaScript NaN]]
|
|
- **참조 맥락:** Referenced whenever extracting fields from objects/arrays, setting defaults, or swapping variables in modern (ES6+) JavaScript.
|
|
|
|
## 📚 출처 (Sources)
|
|
- [S1] W3Schools — JavaScript Destructuring — https://www.w3schools.com/js/js_destructuring.asp
|
|
|
|
## 📝 변경 이력 (Change history)
|
|
- 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Destructuring" page (Astra wiki-curation, P-Reinforce v3.1 format).
|