Double negation(!!-Not Not) in JavaScript

PaperInFlames
Sep 27, 2023

Double negation converts a non-boolean to an inverted boolean value. This helps in checking the truthiness of a value, by representing it as a boolean value.

  1. If the value is a string type, and it is an empty string, false will be returned. If it has some value then true will be returned.
  2. If the value is a number type, and it is 0, false will be returned. If it has some number as a value then true will be returned.
  3. Whereas null and undefined types will be checked for values, hence false will be returned.

4. If the value is a boolean type, then true will be returned if the value is true else false will be returned.

Hope this helps 😀🫠

--

--