JS Daily 25 - Double Negating a Value

Published on 15 Dec, 2020

What is the output of following code?

const str = "Backbencher";
console.log(!!str);
----o----

The output is true.

This is the easiest way to convert any value to its equivalent boolean value. First negation(!) converts the value to boolean, but it will be inversed. We then use one more negation to invert the value again.