typeof 和 instanceof

来源:互联网 发布:防范电信网络诈骗 编辑:程序博客网 时间:2024/05/17 20:34
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var a = 12;
console.log(typeof a);
console.log(a instanceof Number);//false
var b = 'small';
console.log(typeof b);//string
console.log(b instanceof String);//false
var c = new String(2);
console.log(c);
console.log(typeof c);//Object
console.log(c instanceof String)//true
</script>
</body>
</html>
0 0