javascript中typeof的使用示例

复制代码 代码如下:

  <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>