標籤:null mono 組合 ber fun ges pre color javascrip
1.資料類型
js的資料類型共有6種
分別是:
數值,字串,布爾值,undefind,null,對象最基本的資料類型有3種:數值,字串,和布爾值對象可以分為3個子類型:狹義的對象,數組,函數狹義的數組和對象是兩種不同的資料群組合方式。而函數其實是處理資料的方法。js把函數當成了一種資料類型,可以像其他類型的資料一樣進行賦值和傳遞2.資料類型判斷三種判斷方法
> typeof> instanceof> Object.ptototype.toString()
實驗資料及傳回值
typeof 123"number"typeof ‘123‘"string"typeof false"boolean"function f(){}typeof f"function"typeof undefined"undefined"typeof v"undefined"typeof window"object"typeof {}"object"typeof []"object"typeof null"object"var arr = [];console.log(Object.prototype.toString.call(arr)) VM1072:2 [object Array]var arr = {};console.log(Object.prototype.toString.call(arr)) VM1075:2 [object Object]
3.null和undefinded
null與undefined都可以表示“沒有”,含義非常相似
區分null和undefindednull是一個表示無的對象,轉為數值時為0;undefined是一個表示無的原始值,轉為數值時為NaN4.布爾值轉換規則:除了下面六個值被轉為false,其他值都視為true。
undefinednullfalse0NaN""或‘‘(Null 字元串)
空數組([])和Null 物件({})對應的布爾值,都是true
if({}){console.log(‘Null 物件是true‘);}VM1115:2 Null 物件是trueif([]){console.log(‘空數組是true‘);}VM1118:2 空數組是true
該博文學習自阮一峰的《JavaScript 標準參考教程(alpha)》
javascript 學習筆記 --資料類型