Details about the five data types in Javascript: javascript Data Types
Undefined
Undefined. Only one undefined value exists.
Null
Only one value, null
Boolean
In javascript, it is true as long as the logical expression does not return undefined and does not return null.
Copy codeThe Code is as follows:
If (3) true
If (null) false
If (undefined) false
Number
String
The char type does not exist in javascript.
You can use single or double quotation marks to define a string.
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
// Var s = "hello ";
// Alert (typeof s); // s is a string type
Var s = new String ("hello"); // s is the object type
Alert (typeof s );
</Script>
</Head>
<Body>
</Body>
</Html>
Typeof is a unary operator used to obtain the data type of a variable.
There are five return values.Undefined, boolean, number, string, and object.
The first four are easy to understand. The last object makes the programmer unable to judge, and only returns the object in general.
In javascript, if the function does not declare the return value, undefined is returned by default.
If the return value is declared, what is actually returned.
Undefined is derived from null, so true is returned for comparison.
Alert (undefined = null); // true
Forced type conversion
In javascript, there are three types of forced conversions:
Boolean (value)
Number (value)
String (value)
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
Var num = Number (3 );
Alert (num );
Var s = "hello ";
Alert (Boolean (s ));
Var s1 = String ("hello ");
Alert (typeof s1 );
Var obj = new String ("hello"); // This Is Not A forced type conversion!
Alert (typeof obj );
</Script>
</Head>
<Body>
</Body>
</Html>
In javascript, all objects are inherited from Object objects.
It is generated in the form of new.
Some methods in js can be enumerated, and some cannot.
You can use the built-in js method to determine whether it can be enumerated.
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
Var object = new Object ();
For (var v in object ){
Console. log (v );
}
Alert (object. propertyIsEnumerable ("prototype"); // false is returned, indicating that no attribute can be enumerated. This also means that the corresponding attributes of sub-objects cannot be enumerated.
</Script>
</Head>
<Body>
</Body>
</Html>
Enumerative custom type attributes
Copy codeThe Code is as follows:
<Html>
<Head>
<Script type = "text/javascript">
Var member = function (name, age ){
This. name = name;
This. age = age;
}
Var m = new member ("liudh", 50 );
For (var v in m ){
Console. log (v );
// Name
// Age
}
Alert (m. propertyIsEnumerable ("prototype"); // false
// For (var v in window ){
// Console. log (v );
//}
</Script>
</Head>
<Body>
</Body>
</Html>