# Boolean

`Boolean` 是布林值的包覆器。

## 語法

`new Boolean([value])`

### 參數

`value` 選擇性

## 說明

``````var x = new Boolean(false);
if (x) {
// this code is executed
}
``````

``````var x = false;
if (x) {
// this code is not executed
}
``````

``````var x = Boolean(expression);     // 較好
var x = new Boolean(expression); // 不要用
``````

``````var myFalse = new Boolean(false);   // 初始值給false，實際上為true
var g = new Boolean(myFalse);       // 想當然耳，true
var myString = new String('Hello'); // 字串物件，'Hello'
var s = new Boolean(myString);      // 依舊為true
``````

## 屬性

`Boolean.length`

`Boolean.prototype` (en-US)

## `Boolean` 實體

### 屬性

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/prototype', 'Properties')}}

### 方法

{{page('/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/prototype', 'Methods')}}

## 範例

### 用 `false` 作為初始值建立 `Boolean` 物件

``````var bNoParam = new Boolean();
var bZero = new Boolean(0);
var bNull = new Boolean(null);
var bEmptyString = new Boolean('');
var bfalse = new Boolean(false);
``````

### 用 `true` 作為初始值建立 `Boolean` 物件

``````var btrue = new Boolean(true);
var btrueString = new Boolean('true');
var bfalseString = new Boolean('false');
var bSuLin = new Boolean('Su Lin');
var bArrayProto = new Boolean([]);
var bObjProto = new Boolean({});
``````

## 規範

ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Boolean' in that specification.
Standard
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Boolean' in that specification.
Standard
ECMAScript (ECMA-262)
The definition of 'Boolean' in that specification.
Living Standard

## 瀏覽器相容性

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) 6.0 (Yes) (Yes)
Feature Android Chrome for Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)