'~' 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.
~~
可以将变量转换为对应的数值
使用默认值可以解决一些数值不合法的计算问题
var x = undefined
var y = ''
var z = null
var result = (x || 0) + (y || 0) + (z || 0)
网友评论