DEV Community

Deep
Deep

Posted on

1

What is the !! (not not) operator in JavaScript?

Converts Object to boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.

!oObject  // inverted boolean
!!oObject // non inverted boolean so true boolean 
Enter fullscreen mode Exit fullscreen mode

Representation

So !! is not an operator, it's just the ! operator twice.

Example :

<CustomModal
  disabled={isDisable}
  title="Delete"
  children="Are you sure you want to delete ?"
  onCancel={() => setDataToDelete(null)}
  onConfirm={() => {}}
  show={!!dataToDelete} //show only accepts boolean
/>;
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
millord profile image
juanmillord

So its a good way to do something only when what you are evaluating is true. Thank you.

Collapse
 
josewhitetower profile image
Jose Torreblanca

Boolean(dataToDelete)

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay