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: JS/JS-en.md
+69
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,75 @@ b.name = 'EF'
50
50
console.log(a) // EF
51
51
```
52
52
53
+
# Type Conversion
54
+
55
+
## Converting to Boolean
56
+
57
+
Other than `undefined`, `null`, `false`, `NaN`, `''`, `0`, `-0`, all of the values, including objects, are converted to `true`.
58
+
59
+
## Objects to Primitive Types
60
+
61
+
When objects are converted, `valueOf` and `toString` will be called, respectively in order. These two methods can also be overridden.
62
+
63
+
```js
64
+
let a = {
65
+
valueOf() {
66
+
return0
67
+
}
68
+
}
69
+
```
70
+
71
+
## Arithmetic Operators
72
+
73
+
Only for additions, if one of the parameters is a string, the other will be converted to the string as well. For all other operations, as long as one of the parameters is a number, the other will be converted to a number.
74
+
75
+
Additions will invoke three types of type conversions: to primitive types, to numbers, and to string.
0 commit comments