JavaScript Language Basics 4

Source: Internet
Author: User

Talk about the variables in JavaScript.

The advantage of using variables in JavaScript is that variables are stored in the computer's memory, and variables are well suited to saving temporary data, and variables have limited lifetimes, when

When the user closes the page or opens a new page, the variable is released.

In JavaScript code, variable names are case-sensitive, and some specific words or characters cannot be used as variable names, and these specific words are in JavaScript

Reserved words, such as: Var, with, and so on, some special characters cannot be used in variable names, such as the & character and percent percent percent character. JavaScript variable names can be used in several

character, but the number cannot be the beginning of a variable name.


Some of the illegal variable names are listed below:

reserved word in Var//javascript

12AD//Digital start

H&DG//contains & characters

H%ji//contains% characters

<span style= "FONT-SIZE:14PX;" ></span>

Some valid variable names are listed below:

Helloworld23

Hello_world

When defining variables, we should use canonical names to name them, such as declaring names:

var name;

Next look at the example code:

<span style= "FONT-SIZE:14PX;" >

The browser loads the file and pops up a message box (alert is a message box):

The variable myname is displayed in the message box as Billgu

At first, there was no assignment for MyName, when the initial value of myname was undefined, then MyName was assigned BILLGU, and alert was invoked as a message box

appears, when you click the OK button, another message box appears:




we can see in the message box that the display is: 1234

when MyName is re-assigned, the original value of the variable is lost, and in JavaScript, a process called garbage collection is automatically

Interpretation put memory that is not being used. When JavaScript detects that a variable is not being used, or a variable that references an object is given a new

Value, the garbage collection process is automatically run to free the memory space that these variables occupy.




reprint Please indicate source: http://blog.csdn.net/hai_qing_xu_kong/article/details/40760675 Emotional Control _ Click to open the link



JavaScript Language Basics 4

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.