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.