JavaScript Variables
Variables in JavaScript are employed for storing information.
Declaring Variables
To declare a variable in JavaScript, take the keyword var or let followed by the variable name.
Example:
var x;
let y;
Variable Naming Rules
The rules for naming variables are as follows.
- Variable names should start with a letter, an underscore (_), or the dollar sign ($).
- Variable names do not begin with numbers.
- Variable names are case-sensitive.
Example:
//valid variable name
let name
=
john;
let _name
=
john;
let $name
=
john;
//invalid variable name
let 2name
=
john;