JavaScript 數據類型

javascript中常見的數據類型有String,Number,Boolean,初次之外還有Object,Undefined,Function,

例如以下代碼:

  1. <script type="text/javascript">  
  2.     function testTypeOf() {  
  3.         var message = "hello";   
  4.         alert(typeof(message)); //string  
  5.         var num = 110;           
  6.         alert(typeof(num));     //number  
  7.         var boo = false;         
  8.         alert(typeof(boo));     //boolean  
  9.         var unde;                
  10.         alert(typeof(unde));    //undefined  
  11.         var fun = function(){return;};   
  12.         alert(typeof(fun));     //function  
  13.         var nul = null;          
  14.         alert(typeof(nul));     //object  
  15.           
  16.         alert(typeof 9);  
  17.     }  
  18.     testTypeOf();  
  19. </script>  
注意,typeof不是一個函數,而是一個操作符,因此typeof 9可以不加括號;

發佈了28 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章