DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Bang bang, you're boolean!
Coding Unicorn πŸ¦„
Coding Unicorn πŸ¦„

Posted on

Bang bang, you're boolean!

❌ If you see code like this:

function isLoggedIn() {
  return user !== undefined;
}
Enter fullscreen mode Exit fullscreen mode

βœ… You can refactor it to:

function isLoggedIn() {
  return !!user;
}
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ A double negation !! converts an object to boolean in accordance with type coercion rules. If the object is one of eight Falsy values defined in JavaScript specification (undefined, null, false, NaN, 0, -0, 0n, ""), the result will be false. Otherwise, it will be true.

🧠 Remember it by:

Bang, bang, you're boolean!

Alt Text

πŸ‘‰ Follow me on Instagram for more coding stuff πŸ¦„

Top comments (15)

Collapse
 
4r7d3c0 profile image
4r7d3c0 • Edited on

Ok thanks nice tip. But why not !==== already :P. And then if you really meant !== then your example is incorrect because if user is null your code would return false which is not the case with !!. Sorry just being pedantic.

(this was written when the post had the following example)

function isLoggedIn() {
  return user !=== undefined;
}
Collapse
 
codingunicorn profile image
Coding Unicorn πŸ¦„ Author • Edited on

Ooops! I've put too many === indeed :-)

Collapse
 
kewbish profile image
Emilie Ma

Despite some of the hate comments, I personally found this good information.

Regardless of content (I'd love to see longer articles in this format, perhaps) - thanks for sharing, don't be discouraged!

Collapse
 
waylonwalker profile image
Waylon Walker

Cool neumonic to remember this by. Your examples 😎

Collapse
 
sanidz profile image
sanidz

Wait what? Instagram for coding stuff?

btw

isLoggedIn = () => !!user

Collapse
 
vilnius2020 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
vilnius2020

Yeah, Instagram for coding stuff XD

it's full of THOT and copy and pasted content from each other.
You don't learn that much except Man show of expensive setups which don't make them better developers and woman who pose as they would advertise for onlyfans.com.

It is very hard to find good content if you are not into that stuff

Collapse
 
abodmicheal profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Abod Micheal (he/him)

What I could see is your pretty cover pictures lol nice article just followed your twitter

Collapse
 
vilnius2020 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
vilnius2020

Dude, she is using you!

She only wants you to join her Instagram and then influence you into giving her money in some way.

It's sad to see that we are also getting THOT.

This site is about coding not fapping...

Collapse
 
codingunicorn profile image
Coding Unicorn πŸ¦„ Author • Edited on

Someone has bad mood today Β―_(ツ)_/Β―

Thread Thread
 
abodmicheal profile image
Abod Micheal (he/him)

Coding unicon take all my money lol, just follow bk

Thread Thread
 
vilnius2020 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
vilnius2020

Google the meaning of a "simp" because you fit it very well xD

Thread Thread
 
abodmicheal profile image
Abod Micheal (he/him)

Lol I was only kidding, taking note of your advice and thank you really

Collapse
 
vilnius2020 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
vilnius2020

Please stop reposting your bad Instagram post...

This is so obvious a funnel to get people to your Instagram account...

at least please take as much time into your post as you do into your pictures...

Collapse
 
patricktingen profile image
Patrick Tingen

Although I value you efforts to fight duplicate content, I don't think you are doing unicorn justice; yes, the pictures seem a bit "too much" for a tech post, but that is up to her.

I scrolled her insta back to 2018 when she started, and she really makes work of the pictures, yet they seem decent enough.

Even though the contents may not be truly original, that should not matter, my guess is that most of the content here is - in one way or another - recycled.

Finally, I'd like to know where she asks for her followers' money since I could not find it.

Collapse
 
vilnius2020 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
vilnius2020

Literally, if you scroll down her Instagram the second post is a thot picture...

Yes, everything is a remix but at least put some effort into it and not just by adding a 5 to an array without even renaming the variables...

Money does not only come from donations ;)

btw: her Instagram states ex-google and in LinkedIn, you don't see anything about it ;)

reminds me of another person named techlead...

πŸŒ–πŸŒ—πŸŒ˜ Turn on dark mode in Settings