Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么会有人使用!!用javascript?_Javascript_Ecmascript 6 - Fatal编程技术网

为什么会有人使用!!用javascript?

为什么会有人使用!!用javascript?,javascript,ecmascript-6,Javascript,Ecmascript 6,当我试图理解vue.js Watcher时,我看到了以下语法!!选项。深我完全理解的含义意味着,但是为什么有人想使用!!true因为它会再次为您提供true 谢谢如果变量是布尔值,那么不会产生任何效果,但如果变量是数字或其他类型,则会将其转换为布尔值 // options if (options) { this.deep = !!options.deep this.user = !!options.user this.lazy = !!options.lazy this.sync

当我试图理解vue.js Watcher时,我看到了以下语法
!!选项。深
我完全理解
的含义意味着,但是为什么有人想使用
!!true
因为它会再次为您提供
true


谢谢

如果变量是布尔值,那么
不会产生任何效果,但如果变量是数字或其他类型,则会将其转换为布尔值

// options
if (options) {
  this.deep = !!options.deep
  this.user = !!options.user
  this.lazy = !!options.lazy
  this.sync = !!options.sync
} else {
  this.deep = this.user = this.lazy = this.sync = false
}

如果变量是布尔值,则
不会产生任何效果,但如果变量是数字或其他类型,则会将其转换为布尔值

// options
if (options) {
  this.deep = !!options.deep
  this.user = !!options.user
  this.lazy = !!options.lazy
  this.sync = !!options.sync
} else {
  this.deep = this.user = this.lazy = this.sync = false
}

是在JavaScript中对布尔值进行强制的一种尝试。使用
布尔(值)

也会得到相同的结果
是在JavaScript中对布尔值进行强制的一种尝试。对于
布尔值(值)

,也会得到相同的结果!!真的
是真的
,但是
也是真的!!1
!!“你好,世界”
。是的
!!真的
是真的,但是
也是真的!!1
!!“你好,世界”