WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Variables


JavaScript Variables

Variables can be thought of as named containers.

JavaScript factors are compartments for putting away information values.

In this precedent, x, y, and z, are variables:

Example

var x = 8;
var y = 7;
var z = x + y;
Try it Yourself »

From the precedent above, you can expect:

  • x stores the esteem 8
  • y stores the esteem 7
  • z stores the esteem 15

Much Like Algebra

In this precedent, item1, item2, and complete, are variables:

Example

var item1 = 8;
var item2 = 7;
var all out = itme1 + item2;
Try it Yourself »

In programming, much the same as in polynomial math, we use factors (like price1) to hold values.

In programming, much the same as in polynomial math, we use factors in articulations (complete = price1 + price2).

From the precedent above, you can ascertain the aggregate to be 11.

JavaScript Identifiers

All JavaScript variables must be identified with unique names.

These remarkable names are called identifiers.

Identifiers can be short names (like x and y), or increasingly graphic names (age, entirety, totalVolume).

The general principles for building names for factors (remarkable identifiers) are:

  • Names can contain letters, digits, underscores, and dollar signs.
  • Names must start with a letter
  • Names can likewise start with $ and _ (however we won't utilize it in this tutorial)
  • Names are case delicate (y and Y are distinctive variables)
  • Reserved words (like JavaScript watchwords) can't be utilized as names

The Assignment Operator

In JavaScript, the equivalent sign (=) is a "assignment" administrator, not an "equal to" operator.

This is not the same as variable based math. The accompanying does not bode well in algebra:

x = x + 8

In JavaScript, be that as it may, it bodes well: it relegates the estimation of x + 8 to x.


JavaScript Data Types

JavaScript factors can hold numbers like 100, and content qualities like "John Doe".

In programming, content qualities are called content strings.

JavaScript can deal with numerous kinds of information, yet for the present, simply consider numbers and strings.

Strings are composed inside twofold or single statements. Numbers are composed without quotes.

If you put statements around a number, it will be treated as a content string.

Example

var pi = 3.14;
var individual = "Sophie";
var answer = 'Yes I am!';
Try it Yourself »