複製代碼代碼如下:
<html>
<head>
<title>javascript中typeof的使用</title>
<script>
//1、基本類型
var x = 123;
var y = "abc";
var z = true;
//alert(typeof x);//number
//alert(typeof y);//string
//alert(typeof z);//boolean
//2、引用類型,型別是object
var arr = new Array();
var date = new Date();
var str = new String("abc");
//alert(typeof arr);//object
//alert(typeof date);//object
//alert(typeof str);//object
//3、物件類型,可以理解為javascript中的類別的模擬是透過function來實現的
alert(typeof Array);//function
alert(typeof Date);//function
alert(typeof String);//function
</script>
</head>
<body>
</body>
</html>