【Javascript】javascript學習 二十六 JavaScript Boolean(邏輯)對象

來源:互聯網
上載者:User

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

執行個體
檢查邏輯值
檢查邏輯對象是 true 還是 false。
完整的 Boolean 對象參考手冊

我們提供 JavaScript Boolean 對象參考手冊,其中包括所有可用於數組對象的屬性和方法。

該手冊包含了對每個屬性和方法的詳細描述以及相關執行個體。

Boolean 對象

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

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

使用關鍵詞 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(true)var myBoolean=new Boolean("true")var myBoolean=new Boolean("false")var myBoolean=new Boolean("Richard")
相關文章

聯繫我們

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