javascript typeof用法小測

來源:互聯網
上載者:User
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
            
            
            function show(){
                //typeof後跟參數,返回的是表示該參數類型的字串
                
                var i = 5.5;     //number
                
                var j = "abc";   //string
                var b = true;    //boolean
                
                var io = new Number("5.5");  //object
                var jo = new String("abc");  //object
                var bo = new Boolean(0);     //object
                
                var bo1 = Boolean(0);
                
              alert(typeof bo1);//boolean
                
                //alert( typeof  alert); //函數的類型都是function
                
                //alert(typeof k);//沒有定義的值(或者理解為不存在)的類型都是undefined
            
                /*
                一些特殊的值
                alert( typeof(NaN) );    //number                
                alert( typeof(Infinity) );//number
                
                alert( typeof  null); //object
                */
                
            }
            
            
     //Boolean 對象
   //建立 Boolean 對象的文法:
     /*       new Boolean(value);    //建構函式
             Boolean(value);        //轉換函式    
             
     參數:
          value 由布爾對象存放的值或者要轉換成布爾值的值。

   傳回值:
                當作為一個建構函式(帶有運算子 new)調用時,Boolean() 將把它的參數轉換成一個布爾值,並且返回一個包含該值的 Boolean 對象。

                如果作為一個函數(不帶有運算子 new)調用時,Boolean() 只將把它的參數轉換成一個原始的布爾值,並且返回這個值。

     注釋:如果省略 value 參數,或者設定為 0、-0、null、""、false、undefined 或 NaN,則該對象設定為 false。否則設定為 true(即使 value 參數是字串 "false")。
    
   */

    </script>
</head>
<body>
<input type="button" value=" click me " onclick="show()"/>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.