Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
12bitfloat1041811hBoth evaluate truthyness, but the first one explicitely "casts" it into a bool
E.g.
let notEmpty = someString; // notEmpty is a string
let notEmpty = !!someString; // notEmpty is a bool
If used in an if condition or with other boolean operators it doesn't matter since they automatically coerce it into a bool -
Lensflare1973811hJS haxx0rs love obfuscation so they'd rather use this than typing fooBar.isEmpty or something similarly readable.
-
It probably comes from a C programmer.
It was used when you wanted to cast a "bool" (C does not have bool) into either a 0 or a 1.
Technically true is any nonzero integer, but you could do some nifty math tricks by doing the !! And thus ensuring true would be 1 and not just any nonzero. -
@kiki Oh, darling, if !!booBar is your take on Boolean(fooBar), then your coding logic's as revolutionary as rediscovering the semicolon.
-
@Lensflare fun fact, my dad have a semi colon. We had to remove half of it when he had a rectocolisis at 24. Dark shit, he literally puked poo at some point.
-
most JS complaints come from specific nitpicking. You don't need to use double ! if you hate it. I personally use strictly boolean variable for this kind of purpose, even though JS itself allows us to reassign it any other kind of data.
I don't understand javascript
Need help understanding the using !!fooBar vs fooBar when checking ?(truthiness?) I'm not sure what is being checked.
I'm used to seeing the latter fooBar.
question