'~' is a bit operation which inverts bits in number. Bitwise operations works with the integer part of number. So if we use '~~' (double inverting) we get our number in integer representation.
~~
可以將變量轉(zhuǎn)換為對(duì)應(yīng)的數(shù)值
將變量轉(zhuǎn)換為對(duì)應(yīng)的數(shù)值
使用默認(rèn)值可以解決一些數(shù)值不合法的計(jì)算問(wèn)題
var x = undefined
var y = ''
var z = null
var result = (x || 0) + (y || 0) + (z || 0)