Undefined
Not defined. Only one value undefined
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 Code code as follows:
if (3) True
if (null) false
if (undefined) false
Number
String
The char type does not exist in JavaScript.
String definitions can be in single quotes, or in double quotes.
Copy Code code as follows:
<script type= "Text/javascript" >
var s= "Hello";
Alert (typeof s);//s is a string type
var s=new String ("Hello");//s is an object type
Alert (typeof s);
</script>
<body>
</body>
typeof is a unary operator that is used to get the data type of a variable
Its return value has five
undefined,boolean,number,string and object.
The first four of them are well understood. And the last object is for the programmer to be unable to judge, only the general return of the object
In JavaScript, if a function does not declare a return value, it returns undefined by default.
If the return value is declared, then what is actually returned.
Undefined is derived from null, so returns True when comparing
alert (undefined==null);//true
Force type conversions
In JavaScript, there are three types of coercion:
Boolean (value)
Number (value)
String (value)
Copy Code code as follows:
<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 mandatory type conversion!
Alert (typeof obj);
</script>
<body>
</body>
In JavaScript, all objects inherit from Object objects.
Generated in the new way.
Some of the methods in JS can be enumerated, and some of them are not.
JS Built-in method can be judged, whether it can be enumerated.
Copy Code code as follows:
<script type= "Text/javascript" >
Var object=new object ();
For (Var v. in object) {
Console.log (v);
}
Alert (Object.propertyisenumerable ("Prototype"))//returns false indicating that there are no attributes that can be enumerated, and that the corresponding property of the child object is also not enumerable
</script>
<body>
</body>
Enumerating properties of custom types
Copy Code code as follows:
<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>
<body>
</body>