JavaScript Variables Tutorial

This JavaScript tutorial aims to explain the theory of JavaScript variables via a demonstration.

Variables are identifiers created merely to serve as containers for values to be stored and retrieved. All variables contain values. The values they contain can be infinitely changed. Variable names once declared however cannnot be changed.

JAVASCRIPT VARIABLE DATA TYPES

In Javascript there are three primary data types storable inside a variable

There are also two composite data types

And two special data types

 

DECLARE A VARIABLE

To declare a JavaScript variable use the var statement.

var x;
var myvar;

INITIALIZE A VARIABLE

A declaration only creates the existence of a variable's identifier within JavaScript. In other words, it assigns a name to a container in which your value(s) will be stored.

To initialize a JavaScript variable you need to assign values to the variables when you declare them

var x=5;
var myvar="initialize";

Note: When you assign a text value to a variable, use quotes around the value.