The data types in js include undefined, boolean, number, string, object, and so on. The first four are the original data types and the first 5th are the reference data types. Next we will share with you the differences between them.
1. Type Analysis:
The data types in js include undefined, boolean, number, string, and object. The first four are original data types and the second are reference data types.
Code
The Code is as follows:
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); // display "undefined"
Alert (typeof a1); // display "undefined"
Alert (typeof a2); // displays "boolean"
Alert (typeof a3); // display "number"
Alert (typeof a4); // display "string"
Alert (typeof a5); // displays "object"
Alert (typeof a6); // displays "object"
Alert (typeof a7); // display "number"
Alert (typeof a8); // display "undefined"
From the code above, we can see that undefined is undefined for undefined values and definitions. null is a special object and NaN is a special number.
2. Comparison
The Code is as follows:
Var a1; // The a1 value is undefined.
Var a2 = null;
Var a3 = NaN;
Alert (a1 = a2); // display "true"
Alert (a1! = A2); // display "false"
Alert (a1 = a3); // display "false"
Alert (a1! = A3); // display "true"
Alert (a2 = a3); // display "false"
Alert (a2! = A3); // display "true"
Alert (a3 = a3); // display "false"
Alert (a3! = A3); // display "true"
From the code above, we can draw a conclusion: (1) undefined is equal to null; (2) NaN is not equal to any value and is not equal to itself.
JavaScript undefined attributes
Definition and usage
The undefined attribute is used to store the undefined value of JavaScript.
Syntax
Undefined
Description
You cannot use the for/in loop to enumerate the undefined attribute, or use the delete operator to delete it.
Undefined is not a constant. You can set it to another value.
Undefined is returned when you try to read non-existent object attributes.
Tips and comments
<The value is equivalent to the undefined operator that the operation is used to test whether a value is undefined, because = "=">
<Indicates no value, but>
Instance
In this example, we will check the undefined one of the two variables:
The Code is as follows: