What are the variable naming conventions in JavaScript ? Last Updated : 30 Jan, 2022 Comments Improve Suggest changes Like Article Like Report When we name variables in javascript, we've to follow certain rules. Each variable should have a name that appropriately identifies it. Your JavaScript code gets easier to comprehend and work with when you use suitable variable names. It's critical to name variables correctly. For example Constants and global variables are always written in uppercase. The following are the rules for naming variables in JavaScript: Spaces are not allowed in variable names.Only letters, digits, underscores, and dollar signs are permitted in variable names.Case matters when it comes to variable names.A letter (alphabet), an underscore (_), or a dollar sign ($) must be the first character in a variable name, any other special characters must not be taken.certain terms such as reserved words in javascript shouldn't be used to name variables. Example 1: Check if variables can be named starting from other symbols. We start the variable name with a hyphen to check whether it's a possible naming convention but it results in an error. JavaScript <script> var #abc = "abc"; console.log(#abc); </script> Output: We get an error because starting the variable name with an # symbol gives an error as it's not the right naming convention. JavaScript <script> var _abc = "abc"; console.log(_abc); </script> Output: Example 2: Check if spaces are allowed. The spaces aren't allowed. an uncaught syntax error is raised. JavaScript <script> var a bc = "abc"; console.log(a bc); </script> Output: Example 3: Variable names are case sensitive. The variable's names are case sensitive that means uppercase letters like 'A' and lowercase letters like 'a' are treated differently. JavaScript <script> // Enabling strict mode "use strict"; // Defining variables of different cases var abc = "bcd"; var ABC = "efg"; console.log(abc); console.log(ABC); console.log(abc == ABC); </script> Output: Example 4: Using reserved words. When we use reserved words to name variables, exceptions are raised. In the below example we use the reserved word "class" and an exception is raised. unexpected token "class". HTML <script> var class = "class"; console.log(class); </script> Output: A few more conventions for good practices: It is good to decide on a case and continue it throughout the code. ex: camel case. code looks elegant and proper.Name your variable with more than one word. This will verify that the name of your variable is accurate.It is suggested not to use variable names that are too short. They do not make proper sense. Comment More infoAdvertise with us Next Article What are the variable naming conventions in JavaScript ? isitapol2002 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads How to Convert String to Variable Name in JavaScript? In JavaScript, if we consider the variable names as string values, it is difficult to transform a variableâs name into a string. However, this problem has been handled in many ways for example, static properties of objects, eval(), and modern ways such as Map can be used to achieve the essential eff 3 min read How to Create a String with Variables in JavaScript? To create a string with variables in JavaScript, you can use several methods, including string concatenation, template literals, and the String methods. Here are the common approaches:1. Template Literals (Recommended)Template literals are the modern and most preferred way to create strings with var 2 min read What characters are valid for JavaScript variable names ? In this article, we will see the valid variable names in JavaScript. The valid variable names can contain letters (both uppercase and lowercase), numbers, underscores, and dollar signs. However, the variable names can not begin with numbers. Some examples of valid variable names: var Geeks; var Geek 2 min read What is Variable Scope in JavaScript ? Variable scope is the context of the program in which it can be accessed. In programming, a variable is a named storage location that holds data or a value. Think of it as a container that you can use to store and manipulate information in your code. Variables allow you to work with data in a flexib 4 min read What are the Gotchas in JavaScript ? Javascript truly is a popular language due to its simplicity and versatility. Despite having many merits, Javascript is a funny language that can confuse you at times especially for those accustomed to the traditional OOP language. The tricky parts or 'gotchas' (not limited to the following) are: == 3 min read How to declare variables in different ways in JavaScript? In JavaScript, variables can be declared using keywords like var, let, or const, each keyword is used in some specific conditions. Understanding these declarations is crucial for managing variable lifetimes and avoiding unintended side effects in code.Table of Content JavaScript varJavaScript letJav 2 min read What is the use of let & const in JavaScript ? In this article, we are going to discuss the usage of let and const in JavaScript with the help of certain theoretical explanations along with some coding example as well. let: let keyword is used to declare variables in JavaScript that are actually to made as block-scoped i.e. it allows us to decla 5 min read Why to avoid global variables in JavaScript ? Global variables are variables that are declared or defined outside any functions in the script. This indicates that global variables can be accessed from anywhere in the particular script and are not restricted to functions or blocks. JavaScript global variables can also be declared from within a f 4 min read How to Declare Multiple Variables in JavaScript? JavaScript variables are used as container to store values, and they can be of any data type. You can declare variables using the var, let, or const keywords. JavaScript provides different ways to declare multiple variables either individually or in a single line for efficiency and readability.Decla 2 min read How to Use Dynamic Variable Names in JavaScript? Dynamic variable names are variable names that are not predefined but are generated dynamically during the execution of a program. This means the name of a variable can be determined at runtime, rather than being explicitly written in the code.Here are different ways to use dynamic variables in Java 2 min read Like