1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| 1 + "2" = "12" 1 + 1 + "2" = "22" 1 + "1" + "2" = "112"
1 + true = 2 1 + false = 1 true + true = 2 false + false = 0 "1" + true = "1true" "1" + false = "1false"
const me = { name: "Charlie", age: 34 } me + 1 = "[object Object]1"
[] + 1 = "1" [1, 2, 3] + [4, 5, 6] = "1,2,3" + "3,4,5" = "1,2,34,5,6"
# Date.valueOf returns a numeric type, but a date will be transformed into a string type when using the + operator. new Date(2020, 11, 1) + 12345 = "Tue Dec 01 2020 00:00:00 GMT+0100 (Central European Standard Time)12345" new Date(2020, 11, 1) + "12345" = "Tue Dec 01 2020 00:00:00 GMT+0100 (Central European Standard Time)12345" new Date(2020, 11, 1).toString() = "Tue Dec 01 2020 00:00:00 GMT+0100 (Central European Standard Time)" new Date(2020, 11, 1).valueOf() = 1606777200000
undefined + 1 = NaN undefined + "1" = "undefined1" null + 1 = 1 null + "1" = "null1" NaN + 1 = NaN NaN + "1" = "NaN1" Symbol(1) + 1 BigInt(1) + 1 BigInt(1) + "2" = "12"
|