<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>javascript025.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<!--
typeof运算符:
js是一门弱类型语言,不代表js是没有类型的。
那么,我们怎么能够知道js的类型呢?
这个时候js就提供了typeof运算符供我们使用。
格式:
typeof 表达式
-->
<script type="text/javascript">
//定义数据
/*
var x = 10;
var y = "hello";
var z = true;
alert(typeof x); //number
alert(typeof y); //string
alert(typeof z); //boolean
*/
//那么,js中哪些内容可以被看做是引用类型的呢
//内置对象:Array,Date,Math,String...
var arr = new Array();
//alert(typeof arr); //object 这是一个对象
alert(typeof Array); //function
var date = new Date();
//alert(typeof date); //object
alert(typeof Date); //function
var str = new String("hello");
//alert(typeof str); //object
alert(typeof String); //function
//三次结果都是function。
//说明了我们其实是可以通过function模拟类的定义。
</script>
</body>
</html>
JavaScript基础(14)—typeof运算符
最新推荐文章于 2019-09-19 10:02:54 发布