Introduction to common variables in JavaScript

Source: Internet
Author: User

JavaScript Declaration variables

JavaScript variables are to save our data, and to declare a variable in Javascrip can be done in the following ways:

(1) Declaring variables with the VAR keyword
(2) You can declare variables and assign values to them at the same time
(3) You can declare one variable at a time, or you can declare more than one variable at a time
(4) If only the variable is not assigned a value, the default value is undefined
(5) If the name of the variable produces an overlay

JavaScript declaration Variable Considerations

(1) Variables are strictly case-sensitive
(2) Variable names do not contain special characters
(3) Variable names are best followed by hump marking or underline method
(4) Variable name best meaning

JavaScript declares variable instances

<! DOCTYPE html>
<meta charset= "Utf-8" >
<title></title>
<script type= "Text/javascript" >
declaring variables
var A;
var b;
var c,d;
alert (a);
Declaring variables at the same time and assigning values
var test= ' This is a teSt ';
var test1=12;
var test2=1.2;
var test3=true;
var Test4=false;
alert (teSt);
Declare multiple variables to be assigned the same initial value
var a=b=c=d=e=1;
alert (a);
The name of the variable will produce an overlay
a=33;
alert (a);
Variable names are strictly case-sensitive
var username= ' King ';
var username= ' QUEEN ';
alert (uSername);
alert (USERNAME);
Variable names are best defined, start with a letter or underscore, and follow the digital letter underline
var age=12;
var test5= ' Hello ';
var 12a= ' BB ';
Alert (12a);
var _test= ' Hello ';
alert (_test);
Hump Marking method
var firstname= ' king ';//Small Hump
var firstname= ' Queen ';//Big Hump
var first_name= ' Maizi ';//Underline method
</Script>
<body>

</body>

Storage and release of JavaScript variables in memory

(1) Collection method: JS is the automatic release of memory, using a useless storage unit collection (garbage Collection) method
(2) Content collection: Our collectors must be able to determine the timing of safe recovery of our memory units, and if we cannot reclaim those values in use, then we should reclaim those values that are no longer in use. Add some values we are using, this time can not be recycled, after recycling will produce errors.
(3) Recovery algorithm: The most commonly used algorithm is to mark and clear the garbage collection of useless storage units, we use a collector, he will periodically traverse all the variables in the running environment, and to the values of these variables to make a mark.

Introduction to common variables in JavaScript

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.