The difference between Nan, null, and undefinded in JavaScript

Source: Internet
Author: User

var A1;var a2 = True;var a3 = 1;var a4 = "Hello"; var a5 = new Object (); var a6 = null;var a7 = nan;var A8 = Undefined;alert   (typeof a); Show "undefined" alert (typeof A1); Show "undefined" alert (typeof A2); Displays "boolean" Alert (typeof A3); Show "number" alert (typeof A4); Displays "string" alert (typeof A5); Show "Object" alert (typeof A6); Show "Object" alert (typeof A7); Show "number" alert (typeof A8); Show "Undefined"

JS data types have undefined,boolean,number,string,object, such as 5, the first 4 are the original type, the 5th is the reference type.

First look at this example above, undefined values and definitions unassigned for Undefined,null is a special Object,nan is a special number (not a number).

var A1; The value of A1 is Undefinedvar a2 = Null;var a3 = nan;alert (A1 = = A2); Show "true" alert (a1! = A2); Show "false" alert (a1 = = A3); Show "false" alert (a1! = A3); Show "true" alert (a2 = = A3); Show "false" alert (a2! = A3); Show "true" alert (a3 = = A3); Show "false" alert (a3! = A3); Show "true"

From the above code, it can be concluded that (1) undefined is equal to NULL, and (2) Nan is not equal to any value, nor is it equal to itself.

Null is an object that represents a null pointer, undefinded is a type that is undefined, and its type is itself called "Undefined type" (and the difference between type object)

The difference between Nan, null, and undefinded 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.