Here are the simple rules to follow to name functions so the code stays clear and easy to understand. With some quick explanations to help keep them in mind.

1. Don’t Clobber Things

Avoid names that are the name of other things in the same scope. Preferring const helps with this, but linters can help out too. Overwriting functionality can cause errors and confusion. This is something that can happen in JavaScript that programmers have to stay vigilant about.

2. Use a Descriptive Verb

Functions are actions to be done, calculations to be calculated, and new objects to come into existence in the programming. It helps to make code read like plain English (or whatever language is spoken by the team) this helps make things easy. Make sure that verb matches what the function does. The verb can be a precursor but usually try to start the function name with a verb.

3. Avoid Namespace Descriptors

Avoid attaching the same word to a group of functions to describe the thing they interact with. Instead, create a class or module and remove the common adjective.

4. Use Consistent Formatting

If most of the program is camelcase and none of it is external API, avoid using _ (underscores) as a spacer and instead use camelcase. Or vice versa, decide this as a team.

Follow the prettier file if one exists, or add one to the project after discussing things with the team.

#coding #javascript

7 Rules You Should Follow When Naming JavaScript Functions
1.50 GEEK