1.6 KiB
1.6 KiB
title, shortTitle, type, tags, author, cover, excerpt, dateModified
| title | shortTitle | type | tags | author | cover | excerpt | dateModified | |||
|---|---|---|---|---|---|---|---|---|---|---|
| JavaScript naming conventions | Naming conventions | story |
|
chalarangelo | naming-conventions | Naming conventions make code easier to read and understand. Learn how to name your variables in JavaScript with this handy guide. | 2021-06-12T19:30:41+03:00 |
Variables
- Names are case-sensitive, lowercase and uppercase are different.
- Start variable names with a letter, use
camelCasefor names. - Variable names should be self-descriptive, describing the stored value.
- Boolean variables are usually prefixed with
isorhas.
Functions
- Names are case-sensitive, lowercase and uppercase are different.
- Start function names with a letter, use
camelCasefor names. - Use descriptive names, usually verbs in the imperative form.
- Common prefixes are
get,make,applyetc. - Class methods follow the same rules.
Constant
- Names are case-sensitive, lowercase and uppercase are different.
- Define constants at the top of your file, function or class.
- Sometimes
UPPER_SNAKE_CASEis used, while other times plaincamelCase.
Classes
- Names are case-sensitive, lowercase and uppercase are different.
- Start class names with a capital letter, use
PascalCasefor names. - Use descriptive names, explaining the functionality of the class.
- Components, which are used in frontend frameworks follow the same rules.
Private
- Prefix any variable or function with
_to show intention for it to be private. - As a convention, this will not prevent other parts of the code from accessing it.