DEV Community

Discussion on: 7 adorable web development tricks

Collapse
brianjenkins94 profile image
Brian Jenkins

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.

Collapse
jacobmparis profile image
Jacob Paris

!! 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.