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/09-object-toprimitive/article.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ In case of such operations, objects are auto-converted to primitives, and then t
9
9
10
10
That's an important limitation, as the result of `obj1 + obj2` can't be another object!
11
11
12
-
E.g. we can't make objects representing vectors or matrices (or archievements or whatever), add them and expect a "summed" object as the result. Such architectural feats are automatically "off the board".
12
+
E.g. we can't make objects representing vectors or matrices (or achievements or whatever), add them and expect a "summed" object as the result. Such architectural feats are automatically "off the board".
13
13
14
14
So, because we can't do much here, there's no maths with objects in real projects. When it happens, it's usually because of a coding mistake.
15
15
@@ -133,7 +133,7 @@ As we can see from the code, `user` becomes a self-descriptive string or a money
133
133
134
134
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
135
135
136
-
- For the "string" hint: `toString`, and if it doesn't exist, then `valueOf` (so `toString` has the priority for stirng conversions).
136
+
- For the "string" hint: `toString`, and if it doesn't exist, then `valueOf` (so `toString` has the priority for string conversions).
137
137
- For other hints: `valueOf`, and if it doesn't exist, then `toString` (so `valueOf` has the priority for maths).
138
138
139
139
Methods `toString` and `valueOf` come from ancient times. They are not symbols (symbols did not exist that long ago), but rather "regular" string-named methods. They provide an alternative "old-style" way to implement the conversion.
@@ -274,4 +274,4 @@ The conversion algorithm is:
274
274
275
275
In practice, it's often enough to implement only `obj.toString()` as a "catch-all" method for string conversions that should return a "human-readable" representation of an object, for logging or debugging purposes.
276
276
277
-
As for math operations, JavaScript doesn't provide a way to "override" them using methods, so real life projects rarely use them on objects.
277
+
As for math operations, JavaScript doesn't provide a way to "override" them using methods, so real life projects rarely use them on objects.
0 commit comments