javascript 學習筆記 --資料類型

來源:互聯網
上載者:User

標籤: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 學習筆記 --資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.