You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/08-symbol/article.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,7 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
53
53
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not accidentally convert one into another.
54
54
55
55
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
56
+
56
57
```js run
57
58
let id = Symbol("id");
58
59
*!*
@@ -61,6 +62,7 @@ alert(id.toString()); // Symbol(id), now it works
61
62
```
62
63
63
64
Or get `symbol.description` property to show the description only:
0 commit comments