Reputation: 1860
There are other questions about !! (double negation) already (here, and here), and these questions answer my confusion about this. But what I want to know with this question is more specific... Here it is my case.
I have eslint set on my codebase, and I fixed all fixable errors recently.
One of these fixes including the double exclamation sign negation.
One example before the fix and after:
// BEFORE eslint fix:
import { IS_DEV } from "./config/clientUrl";
const sandboxMode = IS_DEV ? true : false;
// AFTER eslint fix:
import { IS_DEV } from "./config/clientUrl";
const sandboxMode = !!IS_DEV;
The fix was correct in detect that it was redundant since is IS_DEV is already a boolean here. So I know the value is either true or false.
So, is there any difference using double negation like this:
const sandboxMode = !!IS_DEV;
and using simply without it:
const sandboxMode = IS_DEV;
This wouldn't be another redundancy in this case?
Upvotes: 0
Views: 1207
Reputation: 1229
A few points to my answer:
true
or false
(a boolean) and NEVER anything else, you can just use this: const sandboxMode = IS_DEV
undefined
), you should use const sandboxMode = !!IS_DEV
which will force sandboxMode
to be a booleansandboxMode
is being consumed!Upvotes: 1