!!一般用来将后面的表达式转换为布尔型的数据(boolean)。

var o={flag:true}; 
var test=!!o.flag;//等效于var test=o.flag||false; 
alert(test); 

由于对null与undefined用!操作符时都会产生true的结果,所以用两个感叹号的作用就在于,如果明确设置了o中flag的值(非null/undefined/0""/等值),自然test就会取跟o.flag一样的值;如果没有设置,test就会默认为false,而不是null或undefined。 

 

相关文章:

  • 2021-12-27
  • 2021-11-22
  • 2021-09-15
  • 2022-12-23
  • 2022-02-08
  • 2021-10-16
  • 2021-10-18
  • 2022-02-26
猜你喜欢
  • 2021-06-30
  • 2022-12-23
  • 2021-12-17
  • 2021-05-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案