Home > Web Front-end > JS Tutorial > Javascript Basic Tutorial Variables_Basic Knowledge

Javascript Basic Tutorial Variables_Basic Knowledge

WBOY
Release: 2016-05-16 16:19:49
Original
860 people have browsed it

Variables in JavaScript are declared using the var keyword (variable).

Copy code The code is as follows:

var school = "beijingyizhong"

You can also use the var keyword to give multiple values ​​to a variable.

Copy code The code is as follows:

var school = "beijingyizhong" , diqu = "beijing" , age = 100;

In addition, unlike java, javascript can store different data types in the same variable. For example

Copy code The code is as follows:

var school = "beijing";
document.write(school);
school = 132134;
document.write(school);

In addition, javascript can be used without declaring variables, for example:

Copy code The code is as follows:

var test1 = "i am teacher" ;
Test2 = test1 "PK yuan" ;
Document.write(test2);

When JavaScript encounters an undeclared variable, it will automatically create a global variable for it. For good usage habits, variables should be declared, which is good for work.

In addition, variable declaration should follow the following rules,

The first letter of a variable can be an uppercase or lowercase English letter, an underscore or the dollar "$" symbol
The remaining letters can be underscores, uppercase and lowercase letters, any numbers, or the dollar sign
The name of a variable cannot be a reserved word or keyword
Here are some legal variable names

Copy code The code is as follows:

var test;
var _beijing;
var $djas;

The following are some illegal variable names

Copy code The code is as follows:

var 4abcd; //Start with number
var asdf"dad; //Single quote is an illegal character
var false; // false is the keyword

The above is the entire content of this article. It is all very basic knowledge. I hope you will like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template