!! is a pretty standard way to convert to Boolean, but I definitely agree on every other point.
if(variable)if(!!variable)
Both of these are identical in javascript. Conditional operators only operate on the truthiness of variables to begin with, and that includes ternary notation. The only time I think I'd use it is when I need to export the truthiness of a variable to another module or API without revealing the actual content — principle of least privelege, or something like that.
Use !! when you need to, but seriously consider whether or not you need to. Most of the time, I think you won't.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
7, 6, and 4 are pretty discouraged.
!!
and>>
have terrible readability.Unless you're just doing something quick and hacky, inline styles violate Separation of Concerns.
!!
is a pretty standard way to convert to Boolean, but I definitely agree on every other point.Both of these are identical in javascript. Conditional operators only operate on the truthiness of variables to begin with, and that includes ternary notation. The only time I think I'd use it is when I need to export the truthiness of a variable to another module or API without revealing the actual content — principle of least privelege, or something like that.
Use
!!
when you need to, but seriously consider whether or not you need to. Most of the time, I think you won't.