Skip to content
loading...
Cover image for Bang bang, you're boolean!

Bang bang, you're boolean!

codingunicorn profile image Coding Unicorn 🦄 twitter logo github logo ・1 min read  

❌ If you see code like this:

function isLoggedIn() {
  return user !== undefined;
}

✅ You can refactor it to:

function isLoggedIn() {
  return !!user;
}

💡 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 🦄

twitter logo DISCUSS (15)
Discussion
markdown guide
 

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;
}
 
 

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!

 

Cool neumonic to remember this by. Your examples 😎

 

Wait what? Instagram for coding stuff?

btw

isLoggedIn = () => !!user

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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...

 

Coding unicon take all my money lol, just follow bk

Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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

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

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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...

 

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.

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

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...

Classic DEV Post from Jul 27 '19

If You Don't Know, Now You Know - GitHub Is Restricting Access For Users From Iran And A Few Other Embargoed Countries

Please help our cause against modern-day discrimination

Coding Unicorn 🦄 profile image
Hi!✌(◕‿-)✌ My name is Julia. I'm a full-stack developer specializing in Java and JavaScript.