Undefined
Undefined. There is only one value undefined
Null
There is only one value, null
Boolean
In javascript, as long as the logical expression does not return undefined or null, it is true.
The code copy is 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 defined in single quotes or double quotes.
The code copy 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
The return value is five undefined, boolean, number, string and object.
The first four are easy to understand. The last object is something that the programmer cannot judge, and only returns the object in a general way
In javascript, if the function does not declare the return value, it will return undefined by default.
If the return value is declared, then what is actually returned is what.
undefined derives from null, so return true when comparing
alert(undefined==null);//true
Cases type conversion
In javascript, there are three types of casts:
Boolean(value)
Number(value)
String(value)
The code copy 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 cast type conversion!
alert(typeof obj);
</script>
</head>
<body>
</body>
</html>
In javascript, all objects are inherited from Object objects.
Generate in new way.
Some methods in js can be enumerated, while some are not.
You can use the built-in js method to determine whether it can be enumerated.
The code copy 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"));//Return false, indicating that there is no enumerable property, which also means that the corresponding properties of the child object cannot be enumerable.
</script>
</head>
<body>
</body>
</html>
Enumerate properties of custom types
The code copy 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>