[{"data":1,"prerenderedAt":1148},["ShallowReactive",2],{"blog-\u002Fblog\u002Fjavascript-symbols-explained-guide":3},{"id":4,"title":5,"body":6,"description":1133,"difficulty":1134,"extension":1135,"framework":1136,"frameworkSlug":1137,"meta":1138,"navigation":322,"order":115,"path":1139,"qaPath":1140,"seo":1141,"stem":1142,"subtopic":1143,"topic":1144,"topicSlug":1145,"updated":1146,"__hash__":1147},"blog\u002Fblog\u002Fjavascript-symbols-explained-guide.md","JavaScript Symbols Explained — Unique Keys, the Global Registry and Well-Known Symbols",{"type":7,"value":8,"toc":1119},"minimark",[9,14,27,31,39,151,169,173,176,239,242,246,272,355,366,370,388,475,485,489,503,548,551,555,566,662,669,673,694,805,816,820,831,893,904,908,915,995,998,1002,1023,1027,1112,1115],[10,11,13],"h2",{"id":12},"the-seventh-primitive","The seventh primitive",[15,16,17,18,22,23,26],"p",{},"ES2015 added a new primitive type to JavaScript: the ",[19,20,21],"strong",{},"Symbol",". Every symbol is guaranteed\n",[19,24,25],{},"unique",", which makes symbols ideal as collision-proof property keys and as special hooks\nthat customize how the language treats your objects. Symbols are one of the more mysterious\ncorners of JavaScript — rarely used directly in app code, but powering iteration, coercion, and\nother behaviors under the hood. Understanding them rounds out your grasp of the object model and\nunlocks metaprogramming techniques.",[10,28,30],{"id":29},"creating-unique-symbols","Creating unique symbols",[15,32,33,34,38],{},"You make a symbol by calling ",[35,36,37],"code",{},"Symbol()",". Each call produces a brand-new, unique value — even\ntwo symbols with the same description are different.",[40,41,46],"pre",{"className":42,"code":43,"language":44,"meta":45,"style":45},"language-js shiki shiki-themes github-light github-dark","const a = Symbol()\nconst b = Symbol('id')      \u002F\u002F optional description (debug label only)\na === b                     \u002F\u002F false\nSymbol('id') === Symbol('id')   \u002F\u002F false always unique\ntypeof a                    \u002F\u002F 'symbol'\n","js","",[35,47,48,72,98,113,139],{"__ignoreMap":45},[49,50,53,57,61,64,68],"span",{"class":51,"line":52},"line",1,[49,54,56],{"class":55},"szBVR","const",[49,58,60],{"class":59},"sj4cs"," a",[49,62,63],{"class":55}," =",[49,65,67],{"class":66},"sScJk"," Symbol",[49,69,71],{"class":70},"sVt8B","()\n",[49,73,75,77,80,82,84,87,91,94],{"class":51,"line":74},2,[49,76,56],{"class":55},[49,78,79],{"class":59}," b",[49,81,63],{"class":55},[49,83,67],{"class":66},[49,85,86],{"class":70},"(",[49,88,90],{"class":89},"sZZnC","'id'",[49,92,93],{"class":70},")      ",[49,95,97],{"class":96},"sJ8bj","\u002F\u002F optional description (debug label only)\n",[49,99,101,104,107,110],{"class":51,"line":100},3,[49,102,103],{"class":70},"a ",[49,105,106],{"class":55},"===",[49,108,109],{"class":70}," b                     ",[49,111,112],{"class":96},"\u002F\u002F false\n",[49,114,116,118,120,122,125,127,129,131,133,136],{"class":51,"line":115},4,[49,117,21],{"class":66},[49,119,86],{"class":70},[49,121,90],{"class":89},[49,123,124],{"class":70},") ",[49,126,106],{"class":55},[49,128,67],{"class":66},[49,130,86],{"class":70},[49,132,90],{"class":89},[49,134,135],{"class":70},")   ",[49,137,138],{"class":96},"\u002F\u002F false always unique\n",[49,140,142,145,148],{"class":51,"line":141},5,[49,143,144],{"class":55},"typeof",[49,146,147],{"class":70}," a                    ",[49,149,150],{"class":96},"\u002F\u002F 'symbol'\n",[15,152,153,154,157,158,160,161,164,165,168],{},"The description is purely for debugging — it does ",[19,155,156],{},"not"," affect identity. Also note ",[35,159,21],{}," is\n",[19,162,163],{},"not a constructor",": ",[35,166,167],{},"new Symbol()"," throws, because symbols are primitives, not objects.",[10,170,172],{"id":171},"symbols-as-property-keys","Symbols as property keys",[15,174,175],{},"A symbol can be used as an object key via computed property syntax. Because it's unique, the key\ncan never collide with any string key or another library's symbol.",[40,177,179],{"className":42,"code":178,"language":44,"meta":45,"style":45},"const id = Symbol('id')\nconst user = { [id]: 123, name: 'Ada' }\nuser[id]    \u002F\u002F 123\nuser.id     \u002F\u002F undefined — the string 'id' is a different key\n",[35,180,181,199,223,231],{"__ignoreMap":45},[49,182,183,185,188,190,192,194,196],{"class":51,"line":52},[49,184,56],{"class":55},[49,186,187],{"class":59}," id",[49,189,63],{"class":55},[49,191,67],{"class":66},[49,193,86],{"class":70},[49,195,90],{"class":89},[49,197,198],{"class":70},")\n",[49,200,201,203,206,208,211,214,217,220],{"class":51,"line":74},[49,202,56],{"class":55},[49,204,205],{"class":59}," user",[49,207,63],{"class":55},[49,209,210],{"class":70}," { [id]: ",[49,212,213],{"class":59},"123",[49,215,216],{"class":70},", name: ",[49,218,219],{"class":89},"'Ada'",[49,221,222],{"class":70}," }\n",[49,224,225,228],{"class":51,"line":100},[49,226,227],{"class":70},"user[id]    ",[49,229,230],{"class":96},"\u002F\u002F 123\n",[49,232,233,236],{"class":51,"line":115},[49,234,235],{"class":70},"user.id     ",[49,237,238],{"class":96},"\u002F\u002F undefined — the string 'id' is a different key\n",[15,240,241],{},"This makes symbols perfect for attaching metadata to objects you don't own (or that mix data\nfrom many sources) without risk of overwriting existing properties.",[10,243,245],{"id":244},"hidden-from-enumeration","Hidden from enumeration",[15,247,248,249,252,253,256,257,256,260,263,264,267,268,271],{},"Symbol-keyed properties are ",[19,250,251],{},"skipped"," by ",[35,254,255],{},"for...in",", ",[35,258,259],{},"Object.keys",[35,261,262],{},"Object.values",",\n",[35,265,266],{},"Object.entries",", and ",[35,269,270],{},"JSON.stringify",". They're effectively invisible to ordinary enumeration\nand serialization.",[40,273,275],{"className":42,"code":274,"language":44,"meta":45,"style":45},"const secret = Symbol('secret')\nconst obj = { [secret]: 42, visible: 1 }\n\nObject.keys(obj)       \u002F\u002F ['visible'] — symbol omitted\nJSON.stringify(obj)    \u002F\u002F '{\"visible\":1}'\n",[35,276,277,295,318,324,338],{"__ignoreMap":45},[49,278,279,281,284,286,288,290,293],{"class":51,"line":52},[49,280,56],{"class":55},[49,282,283],{"class":59}," secret",[49,285,63],{"class":55},[49,287,67],{"class":66},[49,289,86],{"class":70},[49,291,292],{"class":89},"'secret'",[49,294,198],{"class":70},[49,296,297,299,302,304,307,310,313,316],{"class":51,"line":74},[49,298,56],{"class":55},[49,300,301],{"class":59}," obj",[49,303,63],{"class":55},[49,305,306],{"class":70}," { [secret]: ",[49,308,309],{"class":59},"42",[49,311,312],{"class":70},", visible: ",[49,314,315],{"class":59},"1",[49,317,222],{"class":70},[49,319,320],{"class":51,"line":100},[49,321,323],{"emptyLinePlaceholder":322},true,"\n",[49,325,326,329,332,335],{"class":51,"line":115},[49,327,328],{"class":70},"Object.",[49,330,331],{"class":66},"keys",[49,333,334],{"class":70},"(obj)       ",[49,336,337],{"class":96},"\u002F\u002F ['visible'] — symbol omitted\n",[49,339,340,343,346,349,352],{"class":51,"line":141},[49,341,342],{"class":59},"JSON",[49,344,345],{"class":70},".",[49,347,348],{"class":66},"stringify",[49,350,351],{"class":70},"(obj)    ",[49,353,354],{"class":96},"\u002F\u002F '{\"visible\":1}'\n",[15,356,357,358,361,362,365],{},"To retrieve symbol keys, you need ",[35,359,360],{},"Object.getOwnPropertySymbols(obj)"," or ",[35,363,364],{},"Reflect.ownKeys(obj)","\n(which returns both string and symbol keys). So symbols give \"soft\" privacy — hidden from casual\nenumeration, but discoverable by code that looks specifically for them.",[10,367,369],{"id":368},"the-global-registry-symbolfor","The global registry: Symbol.for",[15,371,372,373,377,378,383,384,387],{},"Sometimes you want the ",[374,375,376],"em",{},"same"," symbol shared across modules or even realms (iframes, workers).\n",[19,379,380],{},[35,381,382],{},"Symbol.for(key)"," looks up or creates a symbol in a process-wide ",[19,385,386],{},"global registry"," by\nstring key, returning the same symbol every time.",[40,389,391],{"className":42,"code":390,"language":44,"meta":45,"style":45},"Symbol.for('app.id') === Symbol.for('app.id')   \u002F\u002F true shared by key\nSymbol('app.id')     === Symbol('app.id')        \u002F\u002F false — local, unique\n\nSymbol.keyFor(Symbol.for('app.id'))   \u002F\u002F 'app.id' — recover the key\n",[35,392,393,424,449,453],{"__ignoreMap":45},[49,394,395,398,401,403,406,408,410,413,415,417,419,421],{"class":51,"line":52},[49,396,397],{"class":70},"Symbol.",[49,399,400],{"class":66},"for",[49,402,86],{"class":70},[49,404,405],{"class":89},"'app.id'",[49,407,124],{"class":70},[49,409,106],{"class":55},[49,411,412],{"class":70}," Symbol.",[49,414,400],{"class":66},[49,416,86],{"class":70},[49,418,405],{"class":89},[49,420,135],{"class":70},[49,422,423],{"class":96},"\u002F\u002F true shared by key\n",[49,425,426,428,430,432,435,437,439,441,443,446],{"class":51,"line":74},[49,427,21],{"class":66},[49,429,86],{"class":70},[49,431,405],{"class":89},[49,433,434],{"class":70},")     ",[49,436,106],{"class":55},[49,438,67],{"class":66},[49,440,86],{"class":70},[49,442,405],{"class":89},[49,444,445],{"class":70},")        ",[49,447,448],{"class":96},"\u002F\u002F false — local, unique\n",[49,450,451],{"class":51,"line":100},[49,452,323],{"emptyLinePlaceholder":322},[49,454,455,457,460,463,465,467,469,472],{"class":51,"line":115},[49,456,397],{"class":70},[49,458,459],{"class":66},"keyFor",[49,461,462],{"class":70},"(Symbol.",[49,464,400],{"class":66},[49,466,86],{"class":70},[49,468,405],{"class":89},[49,470,471],{"class":70},"))   ",[49,473,474],{"class":96},"\u002F\u002F 'app.id' — recover the key\n",[15,476,477,478,480,481,484],{},"Use plain ",[35,479,37],{}," for guaranteed-unique local keys, and ",[35,482,483],{},"Symbol.for"," when different parts of\na system must agree on one symbol. Registered symbols live for the realm's lifetime and aren't\ngarbage-collected, so don't over-populate the registry.",[10,486,488],{"id":487},"well-known-symbols","Well-known symbols",[15,490,491,492,495,496,498,499,502],{},"The most important use of symbols is the set of ",[19,493,494],{},"well-known symbols"," — built-in symbols\nexposed as static properties on ",[35,497,21],{}," that let you ",[19,500,501],{},"hook into language operations",".\nImplementing the right one customizes how your object behaves with core syntax.",[40,504,506],{"className":42,"code":505,"language":44,"meta":45,"style":45},"Symbol.iterator        \u002F\u002F makes an object iterable (for...of, spread)\nSymbol.asyncIterator   \u002F\u002F for await...of\nSymbol.toPrimitive     \u002F\u002F controls type coercion\nSymbol.toStringTag     \u002F\u002F customizes Object.prototype.toString\nSymbol.hasInstance     \u002F\u002F customizes instanceof\n",[35,507,508,516,524,532,540],{"__ignoreMap":45},[49,509,510,513],{"class":51,"line":52},[49,511,512],{"class":70},"Symbol.iterator        ",[49,514,515],{"class":96},"\u002F\u002F makes an object iterable (for...of, spread)\n",[49,517,518,521],{"class":51,"line":74},[49,519,520],{"class":70},"Symbol.asyncIterator   ",[49,522,523],{"class":96},"\u002F\u002F for await...of\n",[49,525,526,529],{"class":51,"line":100},[49,527,528],{"class":70},"Symbol.toPrimitive     ",[49,530,531],{"class":96},"\u002F\u002F controls type coercion\n",[49,533,534,537],{"class":51,"line":115},[49,535,536],{"class":70},"Symbol.toStringTag     ",[49,538,539],{"class":96},"\u002F\u002F customizes Object.prototype.toString\n",[49,541,542,545],{"class":51,"line":141},[49,543,544],{"class":70},"Symbol.hasInstance     ",[49,546,547],{"class":96},"\u002F\u002F customizes instanceof\n",[15,549,550],{},"These are the connective tissue between your objects and the language's built-in behaviors.",[10,552,554],{"id":553},"symboliterator-making-objects-iterable","Symbol.iterator — making objects iterable",[15,556,557,558,561,562,565],{},"Defining ",[35,559,560],{},"[Symbol.iterator]()"," (often as a generator method) makes your object work with\n",[35,563,564],{},"for...of",", spread, and destructuring.",[40,567,569],{"className":42,"code":568,"language":44,"meta":45,"style":45},"const range = {\n  *[Symbol.iterator]() {\n    yield 1; yield 2; yield 3\n  }\n}\n[...range]                  \u002F\u002F [1, 2, 3]\nfor (const n of range) {}   \u002F\u002F works\n",[35,570,571,583,591,615,620,625,640],{"__ignoreMap":45},[49,572,573,575,578,580],{"class":51,"line":52},[49,574,56],{"class":55},[49,576,577],{"class":59}," range",[49,579,63],{"class":55},[49,581,582],{"class":70}," {\n",[49,584,585,588],{"class":51,"line":74},[49,586,587],{"class":55},"  *",[49,589,590],{"class":70},"[Symbol.iterator]() {\n",[49,592,593,596,599,602,605,608,610,612],{"class":51,"line":100},[49,594,595],{"class":55},"    yield",[49,597,598],{"class":59}," 1",[49,600,601],{"class":70},"; ",[49,603,604],{"class":55},"yield",[49,606,607],{"class":59}," 2",[49,609,601],{"class":70},[49,611,604],{"class":55},[49,613,614],{"class":59}," 3\n",[49,616,617],{"class":51,"line":115},[49,618,619],{"class":70},"  }\n",[49,621,622],{"class":51,"line":141},[49,623,624],{"class":70},"}\n",[49,626,628,631,634,637],{"class":51,"line":627},6,[49,629,630],{"class":70},"[",[49,632,633],{"class":55},"...",[49,635,636],{"class":70},"range]                  ",[49,638,639],{"class":96},"\u002F\u002F [1, 2, 3]\n",[49,641,643,645,648,650,653,656,659],{"class":51,"line":642},7,[49,644,400],{"class":55},[49,646,647],{"class":70}," (",[49,649,56],{"class":55},[49,651,652],{"class":59}," n",[49,654,655],{"class":55}," of",[49,657,658],{"class":70}," range) {}   ",[49,660,661],{"class":96},"\u002F\u002F works\n",[15,663,664,665,668],{},"Every built-in iterable (Array, Map, Set, String) implements this symbol — it ",[374,666,667],{},"is"," the iteration\nprotocol, and symbols are what keep it collision-free.",[10,670,672],{"id":671},"symboltoprimitive-controlling-coercion","Symbol.toPrimitive — controlling coercion",[15,674,557,675,678,679,682,683,256,686,689,690,693],{},[35,676,677],{},"[Symbol.toPrimitive](hint)"," lets an object decide how it converts to a primitive. The\n",[35,680,681],{},"hint"," is ",[35,684,685],{},"'number'",[35,687,688],{},"'string'",", or ",[35,691,692],{},"'default'"," depending on context.",[40,695,697],{"className":42,"code":696,"language":44,"meta":45,"style":45},"const money = {\n  amount: 5,\n  [Symbol.toPrimitive](hint) {\n    return hint === 'string' ? `$${this.amount}` : this.amount\n  }\n}\n`${money}`   \u002F\u002F '$5'  (string hint)\nmoney * 2    \u002F\u002F 10    (number hint)\n",[35,698,699,710,720,731,770,774,778,791],{"__ignoreMap":45},[49,700,701,703,706,708],{"class":51,"line":52},[49,702,56],{"class":55},[49,704,705],{"class":59}," money",[49,707,63],{"class":55},[49,709,582],{"class":70},[49,711,712,715,718],{"class":51,"line":74},[49,713,714],{"class":70},"  amount: ",[49,716,717],{"class":59},"5",[49,719,263],{"class":70},[49,721,722,725,728],{"class":51,"line":100},[49,723,724],{"class":70},"  [Symbol.toPrimitive](",[49,726,681],{"class":727},"s4XuR",[49,729,730],{"class":70},") {\n",[49,732,733,736,739,741,744,747,750,753,755,758,761,764,767],{"class":51,"line":115},[49,734,735],{"class":55},"    return",[49,737,738],{"class":70}," hint ",[49,740,106],{"class":55},[49,742,743],{"class":89}," 'string'",[49,745,746],{"class":55}," ?",[49,748,749],{"class":89}," `$${",[49,751,752],{"class":59},"this",[49,754,345],{"class":89},[49,756,757],{"class":70},"amount",[49,759,760],{"class":89},"}`",[49,762,763],{"class":55}," :",[49,765,766],{"class":59}," this",[49,768,769],{"class":70},".amount\n",[49,771,772],{"class":51,"line":141},[49,773,619],{"class":70},[49,775,776],{"class":51,"line":627},[49,777,624],{"class":70},[49,779,780,783,786,788],{"class":51,"line":642},[49,781,782],{"class":89},"`${",[49,784,785],{"class":70},"money",[49,787,760],{"class":89},[49,789,790],{"class":96},"   \u002F\u002F '$5'  (string hint)\n",[49,792,794,797,800,802],{"class":51,"line":793},8,[49,795,796],{"class":70},"money ",[49,798,799],{"class":55},"*",[49,801,607],{"class":59},[49,803,804],{"class":96},"    \u002F\u002F 10    (number hint)\n",[15,806,807,808,811,812,815],{},"This single hook overrides the default ",[35,809,810],{},"valueOf","\u002F",[35,813,814],{},"toString"," dance with precise control over\ncoercion in different contexts.",[10,817,819],{"id":818},"symbols-and-private-ish-fields","Symbols and private-ish fields",[15,821,822,823,826,827,830],{},"Because symbol keys are hidden from enumeration and serialization, they're sometimes used for\n\"internal\" properties. But this is ",[19,824,825],{},"soft"," privacy — anyone with the symbol or via\n",[35,828,829],{},"Object.getOwnPropertySymbols"," can still access them.",[40,832,834],{"className":42,"code":833,"language":44,"meta":45,"style":45},"const _balance = Symbol('balance')\nclass Account {\n  constructor() { this[_balance] = 0 }   \u002F\u002F hidden from JSON\u002Fkeys, but not truly private\n}\n",[35,835,836,854,864,889],{"__ignoreMap":45},[49,837,838,840,843,845,847,849,852],{"class":51,"line":52},[49,839,56],{"class":55},[49,841,842],{"class":59}," _balance",[49,844,63],{"class":55},[49,846,67],{"class":66},[49,848,86],{"class":70},[49,850,851],{"class":89},"'balance'",[49,853,198],{"class":70},[49,855,856,859,862],{"class":51,"line":74},[49,857,858],{"class":55},"class",[49,860,861],{"class":66}," Account",[49,863,582],{"class":70},[49,865,866,869,872,874,877,880,883,886],{"class":51,"line":100},[49,867,868],{"class":55},"  constructor",[49,870,871],{"class":70},"() { ",[49,873,752],{"class":59},[49,875,876],{"class":70},"[_balance] ",[49,878,879],{"class":55},"=",[49,881,882],{"class":59}," 0",[49,884,885],{"class":70}," }   ",[49,887,888],{"class":96},"\u002F\u002F hidden from JSON\u002Fkeys, but not truly private\n",[49,890,891],{"class":51,"line":115},[49,892,624],{"class":70},[15,894,895,896,899,900,903],{},"For ",[19,897,898],{},"hard"," privacy, use class ",[35,901,902],{},"#private"," fields, which are genuinely inaccessible from outside.\nSymbols are for collision-avoidance, not security.",[10,905,907],{"id":906},"no-implicit-string-coercion","No implicit string coercion",[15,909,910,911,914],{},"Symbols deliberately ",[19,912,913],{},"don't auto-coerce"," to strings, to avoid silent bugs. Implicit\nconversion (concatenation, template slots) throws; you must convert explicitly.",[40,916,918],{"className":42,"code":917,"language":44,"meta":45,"style":45},"const s = Symbol('id')\n'' + s        \u002F\u002F TypeError\n`${s}`        \u002F\u002F TypeError\nString(s)     \u002F\u002F 'Symbol(id)' explicit\ns.toString()  \u002F\u002F 'Symbol(id)'\ns.description \u002F\u002F 'id'\n",[35,919,920,937,951,963,974,987],{"__ignoreMap":45},[49,921,922,924,927,929,931,933,935],{"class":51,"line":52},[49,923,56],{"class":55},[49,925,926],{"class":59}," s",[49,928,63],{"class":55},[49,930,67],{"class":66},[49,932,86],{"class":70},[49,934,90],{"class":89},[49,936,198],{"class":70},[49,938,939,942,945,948],{"class":51,"line":74},[49,940,941],{"class":89},"''",[49,943,944],{"class":55}," +",[49,946,947],{"class":70}," s        ",[49,949,950],{"class":96},"\u002F\u002F TypeError\n",[49,952,953,955,958,960],{"class":51,"line":100},[49,954,782],{"class":89},[49,956,957],{"class":70},"s",[49,959,760],{"class":89},[49,961,962],{"class":96},"        \u002F\u002F TypeError\n",[49,964,965,968,971],{"class":51,"line":115},[49,966,967],{"class":66},"String",[49,969,970],{"class":70},"(s)     ",[49,972,973],{"class":96},"\u002F\u002F 'Symbol(id)' explicit\n",[49,975,976,979,981,984],{"class":51,"line":141},[49,977,978],{"class":70},"s.",[49,980,814],{"class":66},[49,982,983],{"class":70},"()  ",[49,985,986],{"class":96},"\u002F\u002F 'Symbol(id)'\n",[49,988,989,992],{"class":51,"line":627},[49,990,991],{"class":70},"s.description ",[49,993,994],{"class":96},"\u002F\u002F 'id'\n",[15,996,997],{},"This strictness is intentional — it surfaces accidental symbol-to-string conversions instead of\nproducing nonsense.",[10,999,1001],{"id":1000},"when-to-use-symbols","When to use symbols",[15,1003,1004,1005,1008,1009,1012,1013,1016,1017,1019,1020,1022],{},"Reach for symbols when you need ",[19,1006,1007],{},"collision-free keys"," for metadata (especially on objects you\ndon't control), ",[19,1010,1011],{},"enum-like unique constants"," that can't be matched by an equal string literal,\nor when you want to ",[19,1014,1015],{},"hook into language features"," via well-known symbols. For serializable\nvalues that cross network\u002Fstorage boundaries, prefer strings — symbols don't survive\n",[35,1018,270],{},". And for true encapsulation, prefer ",[35,1021,902],{}," fields.",[10,1024,1026],{"id":1025},"key-takeaways","Key takeaways",[1028,1029,1030,1046,1065,1076,1096,1105],"ul",{},[1031,1032,1033,1034,1036,1037,682,1039,1042,1043,1045],"li",{},"A ",[19,1035,21],{}," is a unique primitive (",[35,1038,144],{},[35,1040,1041],{},"'symbol'","); ",[35,1044,167],{}," throws. The\ndescription is a debug label only.",[1031,1047,1048,1049,1052,1053,811,1055,811,1057,1059,1060,361,1062,345],{},"Symbol keys are ",[19,1050,1051],{},"collision-free"," and hidden from ",[35,1054,255],{},[35,1056,259],{},[35,1058,270],{}," —\nretrieve them with ",[35,1061,829],{},[35,1063,1064],{},"Reflect.ownKeys",[1031,1066,1067,1069,1070,1072,1073,1075],{},[35,1068,382],{}," shares a symbol via the ",[19,1071,386],{},"; plain ",[35,1074,37],{}," is locally\nunique.",[1031,1077,1078,647,1080,256,1083,256,1086,256,1089,263,1092,1095],{},[19,1079,488],{},[35,1081,1082],{},"iterator",[35,1084,1085],{},"asyncIterator",[35,1087,1088],{},"toPrimitive",[35,1090,1091],{},"toStringTag",[35,1093,1094],{},"hasInstance",") hook into core language behavior.",[1031,1097,1098,1099,1101,1102,1104],{},"Symbols give ",[19,1100,825],{}," privacy; use ",[35,1103,902],{}," fields for real encapsulation.",[1031,1106,1107,1108,1111],{},"Symbols never implicitly stringify — convert with ",[35,1109,1110],{},"String(sym)","; they don't survive JSON.",[15,1113,1114],{},"Symbols are the quiet machinery behind iteration, coercion, and collision-free keys — knowing\nthem turns \"magic\" language behavior into something you can customize deliberately.",[1116,1117,1118],"style",{},"html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":45,"searchDepth":74,"depth":74,"links":1120},[1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132],{"id":12,"depth":74,"text":13},{"id":29,"depth":74,"text":30},{"id":171,"depth":74,"text":172},{"id":244,"depth":74,"text":245},{"id":368,"depth":74,"text":369},{"id":487,"depth":74,"text":488},{"id":553,"depth":74,"text":554},{"id":671,"depth":74,"text":672},{"id":818,"depth":74,"text":819},{"id":906,"depth":74,"text":907},{"id":1000,"depth":74,"text":1001},{"id":1025,"depth":74,"text":1026},"Understand JavaScript Symbols — unique primitive keys, Symbol.for and the global registry, hidden properties, and well-known symbols like Symbol.iterator and Symbol.toPrimitive that hook into the language.","medium","md","JavaScript","javascript",{},"\u002Fblog\u002Fjavascript-symbols-explained-guide","\u002Fjavascript\u002Fmodern\u002Fsymbols",{"title":5,"description":1133},"blog\u002Fjavascript-symbols-explained-guide","Symbols","Modern JavaScript (ES6+)","modern","2026-06-18","L4c0Q5HhjMVXpFLeLMuMZi9HD6b2AjPAgexBaAzj_HU",1781808673080]