DEV Community

Cover image for 7 adorable web development tricks

7 adorable web development tricks

Arek Nawo on May 01, 2019

This post is taken from my blog, so be sure to check it out for more up-to-date content 😉 By now, all of major web development languages can be co...
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.

Collapse
 
rkichenama profile image
Richard Kichenama

Nice. 1 seems nice, but new elements to the editable style block will be wrapped in divs so won't be processed as style rules, but you can edit existing rules i.e adding rules to the body block, but not add a rule for .some-class

Collapse
 
dbanty profile image
Dylan Anthony

I have a coworker who is always angry about the !! operator, but we use TypeScript so if you don’t turn your truthy value into a Boolean sometimes it won’t compile!

Nice post 👍🏻

Collapse
 
pavelloz profile image
Paweł Kowalski • Edited

You can always use Boolean(var) if you think its worth it ;)

Collapse
 
areknawo profile image
Arek Nawo

Same!

Collapse
 
kyleljohnson profile image
Kyle Johnson

CSS centering is definitely a trick. Sometimes it works and sometimes it doesn't

Collapse
 
trjones1 profile image
Tramel Jones

Cute!

Collapse
 
fazaleqadir011 profile image
fazaleqadir

Thanks for ever