Skip to content

Instantly share code, notes, and snippets.

@lacymorrow
Created November 2, 2023 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lacymorrow/e20cbfb99ba695582a680f9fb2a16e2e to your computer and use it in GitHub Desktop.
Save lacymorrow/e20cbfb99ba695582a680f9fb2a16e2e to your computer and use it in GitHub Desktop.
Javascript Dev Best Practices

Best Practices for Good Javascript

These are personal observations I keep for myself

Naming

Name your files like-this.file or likeThis.file, dashes allow you to delete one word at a time, camelCase allows IDE snippets to automatically scaffold the name.

Debugging

  • Always prefix your console.logs so that you can find rogue logs easily.
  • Use console.error for errors, duh.
  • If you want to keep a console statement permanently, use console.info or console.warn

Data Fetching

Think about how you plan to use your data.

  • Do you need it for SEO? Then static and/or server render it
  • Does it depend on user interaction, like a date range for a graph? Probably client-side, you can componentize or use in useEffect
  • Does it need to be refreshed? In realtime, Then you may want SWR. If on page load, use revalidation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment