DEV Community

Discussion on: JavaScript Best Practices — Designing Functions

Collapse
 
salyadav profile image
Saloni Yadav

A wonderful article!
I learnt some of the things mentioned here the hard way with experience. When I had to revisit an year old code with poor function names and no description.

Some additional important points to remember-

  1. Always try to write a small two line description of what the function does, commented above it.
  2. Name the variables like you name your child. Don’t just use x and y everywhere.
  3. In case of JS, try to differentiate a private function from an fireevent function using _functionName
Collapse
 
aumayeung profile image
John Au-Yeung

That makes sense.

It's hard to forget if they're descriptive enough.

If your code doesn't explain everything, you can always add some comments.