Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 521 Bytes

008-Problems-in-Code-Style.md

File metadata and controls

21 lines (16 loc) · 521 Bytes

Problems in Code Style

Boolean Coercion

Depending on your preferred code style, you may want to get rid of != null when a boolean coercion would work.

Warning
Regardless, keep in mind that if the value might be false, '', 0, or NaN, then a boolean coercion may not work as expected.

if (currentUser() != null) {
  let left;
  sendMessage((left = customMessage()) != null ? left : 'Hello');
}
if (currentUser()) {
  sendMessage(customMessage() || 'Hello');
}