Skip to content

Commit f505ecb

Browse files
authored
Update conditions for choosing between toString and valueOf
1 parent 7000ede commit f505ecb

File tree

1 file changed

+2
-2
lines changed
  • 1-js/04-object-basics/09-object-toprimitive

1 file changed

+2
-2
lines changed

1-js/04-object-basics/09-object-toprimitive/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ As we can see from the code, `user` becomes a self-descriptive string or a money
136136

137137
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
138138

139-
- For the `"string"` hint: call `toString` method, and if it doesn't exist, then `valueOf` (so `toString` has the priority for string conversions).
140-
- For other hints: `valueOf`, and if it doesn't exist, then `toString` (so `valueOf` has the priority for maths).
139+
- For the `"string"` hint: call `toString` method, and if it doesn't exist or if it returns an object instead of a primitive value, then call `valueOf` (so `toString` has the priority for string conversions).
140+
- For other hints: call `valueOf`, and if it doesn't exist or if it returns an object instead of a primitive value, then call `toString` (so `valueOf` has the priority for maths).
141141

142142
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.
143143

0 commit comments

Comments
 (0)