Variables In Javascript
To store any information in javascript we use variables. Variables are containers for storing data.
In syntax, We declare the name of the variable using the keyword which can either be var, let, or const then we assign the value to the variable using the assignment operator.
var — “var “variables can be updated and re-declared within its scope;
let— The let keyword is almost same as var. “let” variables can be updated but not re-declared. As you can see we are getting an error in (figure b)
const — “const” is like let, but the value of the variable can’t be changed. As you can see we are getting an error when we assign the value to language variables in figure c.
Const variables can neither be updated nor re-declared.
Limitations
There are few limitations on the declaration of variable names in JavaScript:
The name should contain just letters, digits, and the symbols dollar($) and underscore(_).
The first character cannot be a number (digit). As we can see when we declare the variable name starting with a number we are getting an error( as shown in figure e).
In Javascript, the variable name is case-sensitive. The variables place and Place are two different variables.
There is a list of reserved words, that cannot be used as variable names because they are used by the language itself.
For example: let, class, return, and function are reserved words.
Note — The variables should be named in a way that allows us to easily understand what’s inside them.