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