JavaScript 中的 instanceof 方法

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>


<script>
var s="hello";
var i=8;
// typeof 只能判断基本数据类型;
alert(typeof (s));
alert(typeof (i));

var s2=new String("hello2");
alert(typeof(s2));
alert( s2 instanceof String);

var n=new Number(2);
alert(typeof (n));
alert( n instanceof String);

</script>
</body>
</html>

相关推荐