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 !! is redundant.
An if condition will coerce the condition into a boolean anyway, as an if condition is either true or 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.
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..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.