Understanding of NULL, Undefined, Nan equivalents, and data types in JS

Source: Internet
Author: User

The data types in JavaScript are null, undefined, number, String, Boolean, object six. The first five are basic data types,

object is a reference type that includes an array, function, and so on.

First Test the types of the various values

var A1;
var a2 = true;
var a3 = 0;
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); Show "Boolean"
Alert (typeof A3); Show "Number"
Alert (typeof A4); Show "string"
Alert (typeof A5); Show "Object"
Alert (typeof A6); Show "Object"
Alert (typeof A7); Show "Number"
Alert (typeof A8); Show "Undefined"

A type of Undefined,nan with a type of number,null that is visible from the undefined variable type is object. Let's do the comparison test again,

var A1;
var a2 = null;
var a3 = NaN;
var a4 = true;
var A5 = "true";
var a6 = 0;
var a7 = undefined;

alert (a1 = = A2); Show "true"
alert (a1 = = A3); Show "false"
alert (A2 = = A3); Show "false"
Alert (a3 = = A3); Show "false"
alert (A2 = = = a3);//display "false"
alert (a4 = = A5);//display "false"
alert (A2 = = A6);//display "false"
alert (a1 = = a7);//Display "true"
alert (A2 = = a7);//Display "true"

Null and undefined equivalents can be seen but not congruent, null and 0 are not equivalent, true and "true" are not equivalent, and Nan is not equal to any value including itself.

Understanding of NULL, Undefined, Nan equivalents, and data types in JS

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.