Files
2nd/10_Wiki/Topic_JavaScript/JavaScript_Symbols.md
T
koriweb 9609c04755 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>
2026-06-23 19:21:18 +09:00

6.4 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
javascript-symbols JavaScript Symbols Frontend draft conceptual
JS symbols
Symbol()
Symbol.for
Symbol.iterator
unique identifier
B 0.87 2026-06-23 2026-06-23
javascript
js
web
frontend
w3schools
symbol
data-types
unique-identifier
https://www.w3schools.com/js/js_datatypes_symbol.asp

JavaScript Symbols

🎯 한 줄 통찰 (One-line insight)

A Symbol is a primitive that represents a unique identifier — every Symbol value is distinct even with identical descriptions — making it ideal for hidden, collision-free object property keys. [S1]

🧠 핵심 개념 (Core concepts)

  • Symbol = unique identifier — a Symbol represents a unique identifier; every Symbol value is distinct, even when created with the same description. [S1]
  • Hidden identifiers — Symbols act as hidden identifiers that no code can accidentally access, preventing property name conflicts when multiple developers work with shared objects. [S1]
  • Optional descriptionSymbol("id") attaches a description (label) without affecting uniqueness. [S1]
  • Symbol.for() is global/shared — symbols created with Symbol.for(key) are looked up in a global registry, so two Symbol.for("id") calls return the same symbol. [S1]
  • typeof a symbol is "symbol" — Symbols have their own primitive type. [S1]

🧩 추출된 패턴 (Extracted patterns)

  • Symbol as object key — use person[id] = 123; (with id a Symbol) to add a property that won't collide with string keys. [S1]
  • Hidden from enumeration/serialization — Symbol properties are excluded from for...in loops and ignored by JSON.stringify(). [S1]
  • Symbol.iterator makes objects iterable — define a [Symbol.iterator]() method returning a next()-based iterator to support for...of. [S1]

📖 세부 내용 (Details)

JavaScript Symbols A Symbol represents a unique identifier. Symbols are hidden identifiers that no code can accidentally access, which helps prevent accidental property conflicts. Every Symbol value is distinct, even with identical descriptions. [S1]

Creating Symbols [S1]

const id1 = Symbol();
const id2 = Symbol();

Symbol Descriptions [S1]

const id = Symbol("id");

Uniqueness — two symbols with the same description are still different: [S1]

const id1 = Symbol("id");
const id2 = Symbol("id");
let result = (id1 === id2);

Symbol as Object Property Key [S1]

const id = Symbol("id");
const person = {
  firstName: "John",
  lastName: "Doe"
};
person[id] = 123;

Type Checkingtypeof of a symbol is "symbol": [S1]

const id = Symbol("id");
let type = typeof id;

Global SymbolsSymbol.for() reuses a shared symbol from a global registry: [S1]

const id1 = Symbol.for("id");
const id2 = Symbol.for("id");
let result = (id1 === id2);

Symbol.iterator Implementation — define a custom iterator so the object works with for...of: [S1]

const myObject = {
  data: ["A", "B", "C"],
  [Symbol.iterator]() {
    let index = 0;
    let data = this.data;
    return {
      next() {
        if (index < data.length) {
          return {value:data[index++], done:false};
        } else {
          return {done:true};
        }
      }
    };
  }
};
let text = "";
for (const x of myObject) {
  text += x + "<br>";
}

Notes on behavior

  • for...in loops — Symbol properties are excluded from for...in iteration, maintaining their hidden nature. [S1]
  • JSON serializationJSON.stringify() ignores Symbol properties entirely. [S1]
  • When to use — recommended for unique property names, hidden properties, custom iterables, and special behaviors, but cautioned against routine use in everyday code. [S1]

🛠️ 적용 사례 (Applied in summary)

The page's own snippets are the canonical applied examples — creating symbols, using one as a person[id] key, the Symbol.for() global lookup, and the Symbol.iterator custom iterable. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Use a Symbol as a collision-free property key (language: JavaScript):

const id = Symbol("id");
person[id] = 123;

Shared global symbol:

const id1 = Symbol.for("id");
const id2 = Symbol.for("id");
let result = (id1 === id2);

⚖️ 비교 및 선택 기준 (Comparison & decision criteria)

  • Symbol() vs Symbol.for()Symbol() always creates a brand-new, unique symbol (even with the same description); Symbol.for(key) returns a shared symbol from the global registry, so repeated calls with the same key are equal. Use Symbol() for truly private keys and Symbol.for() when the same symbol must be retrievable across code. [S1]
  • Symbol key vs string key — Symbol keys are hidden from for...in and JSON.stringify(), unlike string keys; choose symbols when a property should not be enumerated or serialized, but prefer ordinary keys for everyday data. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

No contradictions found in the source. The page advises against routine use of Symbols in everyday code. [S1]

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.87
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Symbols" page (Astra wiki-curation, P-Reinforce v3.1 format).