Basic Javascript tutorials-basics-js tutorials

Source: Internet
Author: User
We all know that javascript can be implicitly named as a variable. However, you must note that the implicit name variable is always created as a global variable. Check the following code to force the declaration of variables in javascript. We recommend that you declare variables using var. Variables in javascript are declared using the var keyword (variable.

The Code is as follows:


Var school = "beijingyizhong"

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

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

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:

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. It is good to declare the variable for good use.

In addition, the variable declaration should follow the following rules,

The first letter of a variable can be a uppercase/lowercase English letter, underscore (_), or dollar "$ ".
The remaining letters can be underscores (_), uppercase/lowercase letters, any number, or dollar "$ ".
Variable names cannot be reserved words or keywords
The following are some valid variable names.

The Code is as follows:


Var test;
Var _ beijing;
Var $ djas;

The following are invalid variable names.

The Code is as follows:


Var 4 abcd; // starts with a number.
Var asdf "dad; // single quotes are invalid characters
Var false; // false is the keyword.

The above is all the content in this article. It is a basic knowledge and I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.