Home / Blog / 6 rules to name variables correctly
6 rules to name variables correctly

6 rules to name variables correctly

  • Anna KoshevaAnna Kosheva
  • January 12, 2023

    January 12, 2023

A developer reads code more often than writes it. In addition, not your own but created by others 👆 Therefore, unsuccessful names of variables — special “repositories” in which information can be placed can significantly increase time spent. So it’s important to name them so that you and your team can understand the code at a glance, even months later.

Rule 1.

Name the variables so that there is no need for comments. And they were as straightforward as possible without context and additional code study.

Rule 2.

The variable name must include letters, numbers, an underscore, and a $ sign.

Rule 3.

Do not use transliteration. Name the variables only in English. If there are problems with the language, use a translator.

Rule 4.

Do not call variables by one letter, do not use abbreviations, and avoid abbreviations except generally accepted ones.

Rule 5.

Capitalize every word except the first. Remember that variables are case-sensitive.

Rule 6.

The variable name should briefly describe its purpose. Use those that are easy to read.

Rule 7.

Do not use JavaScript-reserved words as variable names.

  • Anna KoshevaAnna Kosheva
  • January 12, 2023

    January 12, 2023

Sign up and don't miss our awesome Mage Mastery lessons and updates!

Related Posts
11 tips for the password safety

11 tips for the password safety

editAnna Kosheva
edit February 17, 2023

Looking to simplify your online activity? Check out our easy password tips and tricks for workdays. Enhance your online security and productivity with these practical tips.

How to be productive with multiple projects?

How to be productive with multiple projects?

editAnna Kosheva
edit February 04, 2023

Managing multiple projects can be a daunting task, but with the right approach, you can stay productive and achieve your goals. Learn more!

How to work with SCRUM?

How to work with SCRUM?

editAnna Kosheva
edit January 23, 2023

Use Scrum for managing and completing complex projects. It is widely used in software development. Learn more here.

If you like this blog post, you may want to watch
Intermediate
 
Max Pronko
Web Icon20 lessons
Clock Icon15 hours 00 mins
Adobe Certified Professional — Magento Commerce Developer Study Group is an 10-week (1.5 hours/week) instructor-led study group. This study group will help PHP and JavaScript developers evaluate their readiness and prepare for the Adobe Certified Professional — Magento Commerce Developer exam.
Beginner
 
Max Pronko
Web Icon13 lessons
Clock Icon1 hour 57 mins
In this free course, you will learn Magento 2 development concepts and gain knowledge of building a fully functional Magento 2 Blog module. The online course will help you develop the necessary skills to become an Adobe Commerce Developer Expert.
2023 © Made with ❤ by Max Pronko