Learn JavaScript Programming

A scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.

JS Introduction
JS Control flow
JS Functions
JS Objects
JS Types
Exceptions and Modules
JS ES6
JavaScript Asynchronous
Miscellaneous

JS Variables

In this tutorial, you will learn about JavaScript variables , how to declare , initialize and use them with the help of examples.

JavaScript Declare Variables

In programming, a variable is a container (storage area) to hold / store data. To declare a variable we use var keyword. For example :


JavaScript Identifiers

All JavaScript variables must be identified with unique names.

These unique names are called identifiers.

Identifiers can be short names (like x, a, b and y) or more descriptive names (personName, age, sum, salary).

The general rules for constructing names for variables (unique identifiers) are:

  1. Names can contain letters, digits, underscores, and dollar signs.

  2. Names must begin with a letter.

  3. Names can also begin with $ and _ .

  4. Variable Names are case sensitive (y and Y are different variables).

  5. Reserved words (like JavaScript keywords) cannot be used as names.

JavaScript Define Variables

After the declaration, the variable has no value (technically it is undefined).

To assign a value to the variable, use the equal sign:

Run code

Share this page on :