Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
May 18, 2020 03:37 am GMT

Bang bang, you're boolean!

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


Original Link: https://dev.to/codingunicorn/bang-bang-you-re-boolean-hoj

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To