JS的boolean 對象

來源:互聯網
上載者:User
Boolean 對象

您可以將 Boolean 對象理解為一個產生邏輯值的對象封裝器。

Boolean(邏輯)對象用於將非邏輯值轉換為邏輯值(true 或者 false)。

建立 Boolean 對象

使用關鍵詞 new 來定義 Boolean 對象。下面的代碼定義了一個名為 myBoolean 的邏輯對象:

var myBoolean=new Boolean()

注釋:如果邏輯對象無初始值或者其值為 0、-0、null、""、false、undefined 或者 NaN,那麼對象的值為 false。否則,其值為 true(即使當自變數為字串 "false" 時)!

下面的所有的程式碼均會建立初始值為 false 的 Boolean 對象。

var myBoolean=new Boolean();var myBoolean=new Boolean(0);var myBoolean=new Boolean(null);var myBoolean=new Boolean("");var myBoolean=new Boolean(false);var myBoolean=new Boolean(NaN);

親自試一試

下面的所有的程式碼均會創初始值為 true 的 Boolean 對象:

var myBoolean=new Boolean(1);var myBoolean=new Boolean(true);var myBoolean=new Boolean("true");var myBoolean=new Boolean("false");var myBoolean=new Boolean("Bill Gates");

親自試一試

聯繫我們

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