↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

8 techniques to write cleaner JavaScript code

The article argues that cleaner JavaScript comes from code that is easier to read, test, and understand. It illustrates each technique with small examples, then rewrites them to reduce hidden dependencies, unclear parameters, repeated property access, and nested async callbacks.

Reading notes
#

  • Pure functions always return the same output for the same inputs and do not change outside variables.
  • When a function has many arguments, passing an object with named properties is clearer than relying on positional parameters.
  • Object and array destructuring reduce repeated property and index access.
  • Hard-coded values should be replaced with named constants so their meaning is visible.
  • Short variable names like t make code harder to trace when the context is not obvious.
  • Object.assign() can help build a new object while applying default values from a config object.
  • Method chaining becomes useful when several methods are meant to be called in sequence on the same object.
  • Promises and async/await make asynchronous code easier to read than nested callbacks.