JavaScript type: Undefined, number, String, object, Boolean

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); 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"

As you can see from the above code, NULL is a special type of object and NaN is a special number type.

Objects that are not defined are undefined types. Objects that define objects but are not assigned are also undefined types.

var A1; The value of A1 is undefined
var 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.

In JavaScript, null and undefined were once confusing. The following analysis helps you to recognize it more clearly (or to make you more confused):

-NULL is a keyword; undefined is a property of the global object

-NULL is an object (Null object, no properties and methods); undefined is a value of type undefined. Try the following code:

Document.writeln (typeof null); Return object
Document.writeln (typeof undefined); return undefined

-Object model, all objects are instances of object or its subclasses, but null object exceptions:
Document.writeln (null instanceof Object); return False

-NULL "equivalent (= =)" In Undefined, but not "full equivalent (= = =)" In undefined:
Document.writeln (null = = undefined); return True
Document.writeln (Null = = = undefined); return False

-When the operation is null and undefined can be converted to false by type, but not equivalent to false:
Document.writeln (!null,!undefined); Return true,true
Document.writeln (Null==false); return False
Document.writeln (Undefined==false); return False

JavaScript type: Undefined, number, String, object, Boolean

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.