JavaScript Basics (2) variables

Source: Internet
Author: User

JavaScript declares variables with the VAR keyword

var variable name;

Declaration Variable name Considerations:

  1. The variable name consists of a letter, a value, a "$" symbol, an underscore
  2. Variable names must begin with a letter, a "$" symbol, or an underscore
  3. Variable names cannot use JavaScript keywords and reserved words
  4. Variable names are case-sensitive

Variables must first be declared and then used

var name = "Tom"; var age;age = 10;

When a variable is not assigned a value, the default is undefined, and the variable can be assigned repeatedly.

Variables can hold any type of value, such as numeric value, String, Boolean, etc.

var a = 5;a = "123"; a = true;

Variables can also be directly assigned using the VAR keyword, such as:

i = 5;

 Note: This creates a variable in a way that does not conform to the specification and creates a global variable.

JavaScript Basics (2) variables

Related Article

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.