Skip to content

Commit a980388

Browse files
authored
symbols, disallow Symbol.for
1 parent f4e2813 commit a980388

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

js/red-javascript-style-guide/readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ const s2 = `Tom says: "That's my ${s}"`;
169169

170170
Prefer `Number.isFinite` over `isNaN`. `Number.isFinite` can also be used for type checking. It returns false if the number is `NaN`, `Infinity`, `-Infinity` or another type. ```typeof x === `number` ``` will return true if `x` is `NaN`, `Infinity`, `-Infinity` as well.
171171

172+
### symbols
173+
174+
175+
```js
176+
const mySymbol = Symbol();
177+
const yourSymbol = Symbol(`A meaningfull description`);
178+
yourSymbol.description;
179+
```
180+
181+
Do not use `Symbol.for` because they are disguised globals. ``` typeof mySymbol === `symbol` ``` for type checking.
182+
172183
### date
173184

174185
Use numbers to store dates. Use the `Date` built-in to display them.

0 commit comments

Comments
 (0)