Skip to content

Commit a38ab40

Browse files
authored
Merge pull request #1250 from paroche/patch-1
Update and rename article.md to Change 'occasional' to 'accidental' w…
2 parents 6e2dad9 + 949bcf6 commit a38ab40

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

1-js/04-object-basics/03-symbol/article.md renamed to 1-js/04-object-basics/03-symbol/Change 'occasional' to 'accidental' where appropriate

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
5050
*/!*
5151
```
5252

53-
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not occasionally convert one into another.
53+
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not accidentally convert one into another.
5454

5555
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
5656
```js run
@@ -72,7 +72,7 @@ alert(id.description); // id
7272

7373
## "Hidden" properties
7474

75-
Symbols allow us to create "hidden" properties of an object, that no other part of code can occasionally access or overwrite.
75+
Symbols allow us to create "hidden" properties of an object, that no other part of code can accidentally access or overwrite.
7676

7777
For instance, if we're working with `user` objects, that belong to a third-party code. We'd like to add identifiers to them.
7878

@@ -92,7 +92,7 @@ alert( user[id] ); // we can access the data using the symbol as the key
9292

9393
What's the benefit of using `Symbol("id")` over a string `"id"`?
9494

95-
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed occasionally, the third-party code probably won't even see it, so it's probably all right to do.
95+
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed accidentally, the third-party code probably won't even see it, so it's probably all right to do.
9696

9797
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
9898

@@ -284,7 +284,7 @@ Symbols are always different values, even if they have the same name. If we want
284284
Symbols have two main use cases:
285285

286286
1. "Hidden" object properties.
287-
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be occasionally processed together with other properties. Also it won't be accessed directly, because another script does not have our symbol. So the property will be protected from occasional use or overwrite.
287+
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be accidentally processed together with other properties. Also it won't be accessed directly, because another script does not have our symbol. So the property will be protected from accidental use or overwrite.
288288

289289
So we can "covertly" hide something into objects that we need, but others should not see, using symbolic properties.
290290

0 commit comments

Comments
 (0)