DEV Community


Discussion on: 2 Ways to Convert Values to Boolean in JavaScript

samanthaming profile image
Samantha Ming Author

Your latter example would be the "implicit" coercion. Under the hood, I believe JavaScript is doing something similar to the !! way, right? So the result would be the same . I don't recall completely unfortunately ...but if you know, let me know and save me a trip to google πŸ˜‚

moopet profile image
Ben Sinclair

It's not really coercion, or I don't think it goes that far. It's just that !! is saying "make this a boolean if it's "truthy" and you can just use the "is it truthy" instead.

Casting to boolean is only useful if you're going to do something like supply it to an API that expects a boolean.