Variables in Javascript basic tutorial

Variables

What is a variable? Literally, a variable is a variable amount; from a programming perspective, a variable is used to A memory that stores certain/certain values

1. JS is a weak data type language; that is, when defining variables, just use var to represent them, or even not write them.

2. The variable data type in js is determined by the js engine

How to define variables, the syntax format is as follows:

var variable name;

Example:

var a;var b;

In this way we define two variables a and b

The variable names can Name it arbitrarily, but follow the naming rules:

1. Variables must start with a letter, underscore (_) or dollar sign ($).

2. Then you can use any number of English letters, numbers, underscores (_) or dollar signs ($).

3. JavaScript keywords and JavaScript reserved words cannot be used.

How to assign a value to a variable

There are two ways to assign a value to a variable

The first one:

var a;

a = 123456;

Second type:

var a=123456;

Variables can be assigned repeatedly

Please see the example, the following code

    javascript 

Note:

1. JS is case sensitive, if the variable a is different from A, it means two variables.

2. Although variables can be used directly without declaring them, they are not standardized and need to be declared first and then used.


Continuing Learning
||
javascript
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!