name = 'Rahul'; or var name = 'Rahul'; or let name ='Rahul';
is the variable,
symbol is assignment operator and
at the end of statements. The
Constants are the special variables, a normal variable can be declared with or without keywords like
and their value can be changed throughout the program. But a constant variable is defined with
const name2 = "Ravi"; //constant variable name2= "Raghav"; // error
We can not give any name to the variables, there are some set of rules we need to follow when we give a name to our variable. Rule 1: A Variable name can only start with alphabets, $ (dollar) or _ (underscore) symbol.
Name1 = "Rahul"; //valid name1 = "Rahul"; //valid &name = "Rahul"; // valid _name = "Rahul"; // valid 1name = "Rahul"; // invalid &name = "Rahul"; // Invalid
let let = "Rahul"; // invalid var let = "Rahul"; // invalid
Rule 3: A variable name must be a sequence of alphabets, numbers, underscore, and $ dollar symbol.
name$_12 = "Rahul"; //valid name&_12 = "Rahul"; // invalid
Rule 4: There must not be any space or gap in the variable name.
name 1 ="Rahul"; //invalid name1 = "Rahul"; // valid
let name; // variable declaration var let; // variable declaration
const name = "Rahul"; // initialization with declaration let age; // declaration age = 20; // initialization
- Variable is a name that is used as a container for the data value.
- We need to follow the Naming variables rules while giving a name to the variable.
People are also reading: