DEV Community

Deep
Deep

Posted on

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)