先起个例子吧~ 这个用的是谋智的js引擎monkey spider
darion.yaphet@localhost.localdomain:/home/darion.yaphet> js
js> var i;
js> print(i)
undefined
js>
js> var j = !!i;
js> print(j)
false
js>
看起来 i 是undefined j经过两次取非运算 !i == true !!i == false 不再是undefined
两个叹号(!!) 会把后面的表达式转换成bool类型 如下~
js> var t = null;
js> print(!!t);
false
js>
js> t = ''
""
js> print(!!t);
false
js>
js>
js> t = 1
1
js> print(!!t);
true
js>
js> t = 0
0
js> print(!!t);
false
js>
js>
js> t = '111'
"111"
js> print(!!t);
true
js>
js> t = '0'
"0"
js> print(!!t);