DEV Community

Discussion on: Stop Writing JavaScript Like This

Collapse
 
kettanaito profile image
Artem Zakharchenko

Instead of writing that outdated ||, use the new ?? operator:

|| is as outdated as function. These two operator have two drastically different semantics:

  • || in case left-hand value is falsy.
  • ?? in case left-hand value is not defined (undefined or null).

Both have their usage and are not interchangeable. ?? is great when false is an intentional value.

Parenthesis in functions is not something you should spend your time on, use Prettier.