# Naming cheatsheet Naming things is hard. Is it? ## Guidelines * Pick **one** naming convention and follow it. Whether it is `likeThis`, or `like_this`, or anyhow else, it does not matter. What matters is consistency in your work. ```js /* Bad */ const pages_count = 5; const shouldUpdate = true; /* Good */ const pagesCount = 5; const shouldUpdate = true; /* Good as well */ const pages_count = 5; const should_update = true; ``` * Name, whether of a variable, method, or something else, should be *short*, *descriptive* and *intuitive*: * **Short**. Variable should not take long to type, and therefore to remember, * **Descriptive**. Name of the variable should reflect what this variable possesses/does in the most efficient way, * **Intuitive**. Name of the variable should read naturally, as close to common speach as possible ```js /* Bad */ const a = 5; // "a" could mean anything const isPaginatable = (postsCount > 10); // "Paginatable" sounds extremely unnatural const shouldPaginatize = (postsCount > 10); // Made up verbs are so much fun! /* Good */ const postsCount = 5; const shouldDisplayPagination = (postsCount > 10); ``` * Name should not duplicate the context when the latter is known, and when removing the context from the name does not decrease its readability: ```js class MenuItem { /* Method name duplicates the context it is in "...MenuItem..." */ handleMenuItemClick = (event) => { ... } /* This way it reads as MenuItem.handleClick() */ handleClick = (event) => { ... } } ``` * Name should reflect expected result: ```js /* Bad */ const isEnabled = (itemsCount > 3); return (