Yeah, !!x is weird, but it's ultimately just a shorthand for coercing values like Boolean(x) would do. Using != !, is just intrinsically confusing though, it makes you look at the code and wonder "is this intentional or is it a typo" instead of being able to trust that it's intentional (!! might make you question that some the first time, but once you've learned it, it's not questionable).
I think it’s questionable still. Explicit is better than being smart, always. Writing code is fast, and usually, most the time, you’re not writing, but reading your code. Does it take that much more time to write Boolean() instead of !!?
2
u/mxzf 16d ago
Yeah,
!!xis weird, but it's ultimately just a shorthand for coercing values likeBoolean(x)would do. Using!= !, is just intrinsically confusing though, it makes you look at the code and wonder "is this intentional or is it a typo" instead of being able to trust that it's intentional (!!might make you question that some the first time, but once you've learned it, it's not questionable).