Previous Next

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.

Example:

//valid variable name
let name = john;
let _name = john;
let $name = john;

//invalid variable name
let 2name = john;
Previous Next