Javascript ! and !! differences
Possible Duplicate:
What is the !! operator in JavaScript?
What is the difference between these two operators? Does !! have special meaning, or does it simply mean you are doing two '!' operations. I know there are "Truth" and "Truthy" concepts in Javascript, but I'm not sure if !! is meant for "Truth"
Writing !!
is a common way of converting a "truthy" or "falsey" variable into a genuine boolean value.
For example:
var foo = null;
if (!!foo === true) {
// Code if foo was "truthy"
}
After the first !
is applied to foo
, the value returned is true
. Notting that value again makes it false
, meaning the code inside the if
block is not entered.
!! is just double !
!true // -> false
!!true // -> true
!! is a common way to cast something to boolean value
!!{} // -> true
!!null // -> false
链接地址: http://www.djcxy.com/p/12654.html
上一篇: 是什么 ”!!” Javascript中的运算符?
下一篇: Javascript! 和! 分歧