Usually, it's quite clear to me whether code I'm writing is clean and easy to understand, but lately, I find myself doing the following a lot in JavaScript:
When a function needs to do something only when a certain option is passed in, I do this:
function foo(shouldBar){
//...
shouldBar && bar();
}
I find it quite clear, but I'm probably going to try to kick this habit because
if(shouldBar){
bar();
}
- is more explicit,
- is easier to understand or devs with less JavaScript experience.
How do you decide whether a particular line of code is "too clever"?