DEV Community

Afia Anjum Preety
Afia Anjum Preety

Posted on

1

๐——๐—ผ๐˜‚๐—ฏ๐—น๐—ฒ ๐—ก๐—ฒ๐—ด๐—ฎ๐˜๐—ถ๐—ผ๐—ป (!!)

Image description

Have you ever come across the !! or "not not" operator?
Well, I encountered it this morning.

In hashtag #JavaScript, using the double negation (!!) in front of a value or expression is a shorthand technique to convert a value into its boolean equivalent.

const falsyValue = NaN;
const truthyValue = 'JavaScript';
Enter fullscreen mode Exit fullscreen mode

! means NOT.

  • The first ! (not) operator converts a value into a Boolean and reverses it, changing truthy values to false and falsy values (e.g., false, 0, null, undefined, NaN, or an empty string) to true.
!falsyValue; // true
!truthyValue // false
Enter fullscreen mode Exit fullscreen mode
  • The second ! operator negates the result of the first !operation, converting the value back to its original boolean representation. If the original value is truthy, it remains true after the double negation, and if it is falsy, it becomes false.
!!falsyValue; // false
!!truthyValue // true
Enter fullscreen mode Exit fullscreen mode

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (3)

Collapse
 
cezarytomczyk profile image
Cezary Tomczyk โ€ข

Sharing article related to stop using double exclamation.

Collapse
 
tkirwa profile image
Tonny Kirwa โ€ข

Great... It's a worthy tip

Collapse
 
2apreety18 profile image
Afia Anjum Preety โ€ข

Thank you ๐Ÿ˜ƒ

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. โค๏ธ