javascript--"Null" and "undefined"

Source: Internet
Author: User

First, undefined:

1, when the declaration variable is not assigned value, then the value of the variable is undefined;

2, when the method does not return a value, the received return value is undefined.

Two, null:

A null value means pointing to an "empty object", which requires us to display a null value assigned to n.

"Note": In general, when an object is used, it needs to be shown that the browser can be garbage collected, it is necessary to explicitly assign the variable to null, so that the object pointed to by this variable can be recycled.

"Special reminder": whether the value of a variable is a null value or undefined indicates that the variable is not available. So before using some variables, you can check the variables to see if the variable is available.

"Method": Var x;

if (typeof (x)! = ' undefined ' &&x!=null) {

Alert (' x available ');

}else{

Alert (' x not available ');

}

javascript--"Null" and "undefined"

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.