1 + - + + + - + 1// 2 +"5"// 5 (string to number) +""// 0 (string to number) +"1 + 2"// NaN (doesn't evaluate) +newDate() // same as (new Date()).getTime() +"foo"// NaN (string to number) +{} // NaN +[] // 0 (toString() returns an empty string list) +[1] // 1 +[1,2] // NaN +newSet([1]) // NaN +BigInt(1) // Uncaught TypeError: Cannot convert a BigInt value to a number +undefined// NaN +null// 0 +true// 1 +false// 0 {}+[] // 0 ({}被看作是一个空代码块,因此 + 在这里仅是一元操作符,等同于+[]) ({})+1// '[object Object]1'
四、++
1 2 3 4 5 6 7 8 9 10 11
functionfuncA(x){ var temp = 4;
functionfuncB(y){ console.log( ++x + y + (temp--)); }