Boolean對象常用屬性及方法詳解

常用屬性

  • constructor 返回對創建此對象的 Boolean 函數的引用
  • prototype 使您有能力向對象添加屬性和方法。

常用方法

  • toString() 把布爾值轉換爲字符串,並返回結果。
  • valueOf() 返回 Boolean 對象的原始值。

會轉化爲false的幾個值
布爾對象無初始值或者其值爲:

  • 0
  • -0
  • null
  • “”
  • false
  • undefined
  • NaN
console.log(new Boolean());       //false
console.log(new Boolean(false));  //false
console.log(new Boolean(0));       //false
console.log(new Boolean(null));//false
console.log(new Boolean(undefined));//false
console.log(new Boolean(    NaN));//false
console.log(new Boolean(""));//false
console.log(new Boolean(0));//false

其餘情況都爲true

發佈了70 篇原創文章 · 獲贊 19 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章