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
-
@Proximyst in JS the first ! coerces the value into a boolean and then, the second ! Inverts that boolean
What i really mean is you use it to turn something into a boolean, eg
"test"
!"test" // false
!!"test" // true
So you turn a "falsy" value into false and a "truthy" value into true -
@ObiSwagKenobi Why not just check if it's truthy then? (Just checking the variable)
-
@Proximyst well it certainly makes the code a lot more readable. If you see a !! you know it's either true or false.
when you're creating an api,let's say for your team, you want your functions to be explicit in what they return. Let's say you have a
const hasUsername = user => !!user.email
It's better to return true or false rather than relying to the other person to check for null/undefined/empty string etc
Not the best example but I hope you get the point 😁
Related Rants
First stage of burn out 😂 😂 😂
joke/meme
coder
burnout
javascript
stress
devlife