[英]eslint for redundant double how to changes to valid
I try to submit the following code 我尝试提交以下代码
if(!!obj){
...
}
redundant double error , how can I fix it ? 冗余双错误,我该如何解决? why I getting it now ...
为什么我现在得到它...
ESLint is giving you the warning as the !! ESLint正在给你警告!! is redundant.
是多余的。
An if condition will coerce the condition into a boolean anyway, as an if condition is either true or false. if条件无论如何都会将条件强制转换为布尔值,因为if条件是true或false。 So what you end up telling the javascript engine to do is, coerce to a boolean true / false, then not the value, and then not the value again, only to get the original coerced value.
所以你最终告诉javascript引擎要做的是,强制转换为布尔值true / false,然后不是值,然后再不是值,只是为了得到原始的强制值。
But saying all this a double !, is not always redundant. 但是说这一切都是双重的,并不总是多余的。 For example say your storing data inside an object, and say you want to force a boolean storage, you could !!value it.
例如,说你在一个对象中存储数据,并说你想强制一个布尔存储,你可以!!重视它。
Sometimes I even use this just to double check what true / false something returns from the console.. eg. 有时我甚至会用它来仔细检查从控制台返回的真/假的内容。例如。
!!'' = false
were as !!'0' = true
and !!0 = false
etc.. !!'' = false
是!!'0' = true
, !!0 = false
等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.