关于JS中的双感叹号

!!variant will return boolean type according to given value.
 
1) !!a will return true when the value is given non-empty string or non-zero number
var a = " "; alert(!!a);
var a = "s"; alert(!!a);
var a = true; alert(!!a);
var a = 1; alert(!!a);
var a = -1; alert(!!a);
var a = -2; alert(!!a);
 
2) !!a will return false when the value is empty string or zero number or null
var a = 0; alert(!!a);
var a = ""; alert(!!a);
var a = false; alert(!!a);

你可能感兴趣的:(Blog)