JavaScript is such a weak type of language, in the judgment of equality is very troublesome, obviously not a thing, but equal. This example shows the equality of NULL, undefined, 0, false, and "". var Arr__java

Source: Internet
Author: User
How to Judge-null js in JS How to judge-undefined JS how to judge-string type of number

The following is an incorrect method: var exp = undefined;
if (exp = = undefined)
{
Alert ("undefined");
}

When exp is null, it also gets the same result as undefined, although null and undefined are different. Note: This method can be used to determine both undefined and null. var exp = undefined;
if (typeof exp = = undefined)
{
Alert ("undefined");
}

typeof returns a string of six possible types: number, String, Boolean, object, function, undefined.

The following is the correct method: var exp = undefined;
if (typeof exp = "undefined")
{
Alert ("undefined");
}

The following are the simpler and more correct methods (if the variable is neither Var nor assigned, the following error occurs, but at this point the programmer, not JavaScript) is to be reviewed: var exp = undefined;
if (exp = = undefined)
{
Alert ("undefined");
}

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.