JS案例:通过typedof测试变量类型示例

来自CloudWiki
跳转至: 导航搜索
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>typeof运算符测试示例</title>
</head><body><pre>
<script type="text/javascript">
	  var a,type_a;
	  a=100; type_a=typeof a; document.writeln("变量a的类型是:"+type_a);
	  a=true; type_a=typeof a; document.writeln("变量a的类型是:"+type_a);
	  a="hello"; type_a=typeof a; document.writeln("变量a的类型是:"+type_a);
	  a=null; type_a=typeof a; document.writeln("变量a的类型是:"+type_a);
</script>
</pre></body></html>