javascript中的基礎資料型別 (Elementary Data Type)

來源:互聯網
上載者:User

標籤:

在javascipt中有五大基礎資料型別 (Elementary Data Type),列表如下:

1、數字

  他們又又包括(正負整數,浮點數)十進位數,十六進位數與八位元,指數和特殊數值NaN,(Infinity,-Infinity)正負無窮

2、字串

     所有包在引號內的字元

3、布爾值

    true or false

4、undefined

    undefined類型的值只有一個:undefined >>>>>>>>>>>>未定義或函數沒有現式傳回值的時候都會出現

5、null 

     null類型的值只有一個:null  

任何不屬於基本類型的都屬於對象(PS:JavaScript中一切皆對象)

 絕大部分值在轉換為布爾值的時候都為true,除了以下6種falsy值:

     "";

     null;

     undefined;

     0;

     NaN;

     false;

 那麼問題來了,怎麼把一個值轉成布爾值呢?

 百度得知,可以使用內建函數Boolean();

 function TomG(){

      console.log(      Boolean(‘‘)    );

      console.log(     Boolean(NaN)          );

      console.log(      Boolean(null)      );

      console.log(      Boolean(false)       );
      console.log(     Boolean(undefined)     );

      console.log(       Boolean(0)        );
      console.log(      Boolean(‘0‘)       );

      console.log(   Boolean(132)        );

 

 TomG();

還有其他方法嗎?改天再看 

 

javascript中的基礎資料型別 (Elementary Data Type)

聯繫我們

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