3.4 資料型態(Data Types)
可以直接在 console 中來測試觀察。
變數的資料型態
請直接在 console 中,輸入以下各範例來觀察變數的資料型態。
可以用 typeof 來檢測變數的資料類型,包含以下:
字串(String)
用雙引號或單引號括起來的,會被視為字串:
數值(Number)
數值的部份,例如 1、1.5 等:
布靈(Boolean)
true 、 false 就是布靈值:
物件(Object)
以 左右大括號 括起:
陣列(Array)
以 左右中括號 括起:
未定義(undefined)
特殊關鍵字:
空(null)
特殊關鍵字:
函式(function)
總結
以上算起來,利用 typeof 回傳的資料類型,總共六個:
"string"
"number"
"boolean"
"object"
"undefined"
"function"
Last updated