Some examples of valid variable names:
var Geeks; var Geeks_for_Geeks; var $Geeks; var _Geeks; var Geeks123;
Some examples of invalid variable names:
var Geeks-for-Geeks; // Hyphens not allowed var 123Geeks; // Can not start with numbers var Geeks for Geeks; // Spaces not allowed
Rules for variable name:
- Spaces are not allowed in variable names.
- Hyphens are not allowed in variable names.
- Only letters, numbers, underscores, and dollar signs are permitted in variable names.
- Case matters when it comes to variable names.
- Variable name always starts with a letter (alphabet), underscore (_), or a dollar sign ($), i.e. any other special characters not allowed.
- Reserved keywords are not allowed.
Example 1: In this example, we will declare some variables with their values and print their sum on the console.
Example 2: In this example, we will declare some variables with values and print their values on the console.
15 20 30 40
Example 3: In this example, we will declare some invalid variables with their values and print them on the console, it displays some error message..
SyntaxError: Invalid or unexpected token
Please Login to comment...