zoukankan      html  css  js  c++  java
  • javascript 中 typeof 的使用

    javascript 中 typeof 的使用

          javascript有五种基本的数据类型(简单数据类型),它们分别是:String、Undefined、Null、Boolean和Number。还有一种复杂数据类型Object。

          typeof可以检测给定变量的数据类型。

          对一个值使用typeof操作符可能返回下列某个字符串:string、number、boolean、undefined、function和object。

    <script type="text/javascript">
    	function testTypeOf() {
    		var message = "hello"; 
    		alert(typeof(message)); //string
    		var num = 110;         
    		alert(typeof(num));     //number
    		var boo = false;       
    		alert(typeof(boo));     //boolean
    		var unde;              
    		alert(typeof(unde));    //undefined
    		var fun = function(){return;}; 
    		alert(typeof(fun));     //function
    		var nul = null;        
    		alert(typeof(nul));     //object
    		
    		alert(typeof 9);
    	}
    	testTypeOf();
    </script>

          注意:typeof是一个操作符而不是函数,因此圆括号可以省略,而不是必须的。

  • 相关阅读:
    JAVA 练习1
    JSP基础
    网络协议
    mysql基础
    python之高级
    powershell基础
    python之迭代器与遍历
    python之面向对象
    linux常用命令
    docker 安装 ElasticSearch:7.4.2
  • 原文地址:https://www.cnblogs.com/new0801/p/6146601.html
Copyright © 2011-2022 走看看