javascript 的基本类型是数字型 字符串 null boolean undefined .复杂类型就是对象 判断基本类型就用typeof 对象就用instanceof ,啥也不说了看代码 请
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<script>
function dd(){
document.writeln(typeof 1); //number
document.writeln(typeof null); //object
document.writeln(typeof (new Number(1))) //number
document.writeln(typeof (function(){})); //function
document.writeln(typeof undefined); //undefined
document.writeln(typeof []); //object
document.writeln(typeof {}); //object
document.writeln(typeof "abc") //string
}
function ss()
{ //经典的面试题
document.writeln(typeof 111+"abc");//numberabc
}
function ww()
{
document.writeln(typeof null===undefined); // false
}
function gg()
{
var fg=function(){}
document.writeln(fg instanceof Object); //true
var df={}
document.writeln(df instanceof Object); //true
var arr=[];
document.writeln(arr instanceof Object); //true
}
</script>
<body>
<input type="button" value="typeof" οnclick="dd()">
<input type="button" value="typeof 优先级" οnclick="ss()">
<input type="button" value="typeof null===undefined" οnclick="ww()">
<input type="button" value="函数对象数组" οnclick="gg()">
</body>
</html>