What does operator !! (not, not) mean in JavaScript?

October 02, 2022 No comments not not operator tips solutions javascript js


In this post, we'll learn what the !! operator does in JavaScript.

The !! operator in JavaScript

The !! converts an Object to boolean. This works similarly to Boolean(object). If the object is falsey (e.g., 0, null, undefined, etc.), it would be false, otherwise, true.

Boolean(object) // Boolean
!object  // Inverted Boolean
!!object // Noninverted Boolean, so true Boolean representation
Boolean(5) === !!5

The !! converts a non-boolean to an inverted boolean (for instance, !5 would be false since 5 is a non-false value in JavaScript), then boolean-inverts that so you get the original value as a boolean (so !!5 would be true).


In this article, we described what the !! operator means in JavaScript, and how to use it.

{{ message }}

{{ 'Comments are closed.' | trans }}