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

Image of Timescale

๐Ÿš€ pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applicationsโ€”without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read 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 ๐Ÿ˜ƒ

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

๐Ÿ‘‹ Kindness is contagious

Please leave a โค๏ธ or a friendly comment on this post if you found it helpful!

Okay