> For the complete documentation index, see [llms.txt](https://docs.activejs.dev/activejs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.activejs.dev/activejs/fundamentals/units/boolunit.md).

# BoolUnit

**BoolUnit** is a type of [Unit](/activejs/fundamentals/units.md) that only accepts `boolean` data type as its value. It ensures that at any point of time the value would always be `boolean`.

It implements non-deprecated [Object.prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) methods like `toString`&#x20;and redirects them to the stored `boolean` value inside the Unit, so when you call `BoolUnit.toString()` , it'll be executed on the Unit's value instead of the BoolUnit instance itself. Similarly, when you call other `Object.prototype` methods they are called on the stored value instead of BoolUnit instance.

See [API reference](https://api.activejs.dev/classes/boolunit) for more details.

|                 |           |
| --------------- | --------- |
| Default value   | `false`   |
| Value data type | `boolean` |

### BoolUnit vs `boolean`

BoolUnit can not be used as a drop-in replacement for primitive `boolean` value, since BoolUnit is a non-primitive data structure, and the actual `boolean` value is stored inside the Unit. See the below comparisons for more clarity.

```typescript
// initialization
let bool = false; // a variable with prmitive boolean value
const unit = new BoolUnit({initialValue: false});
// initialValue is optional, BoolUnit has false as default value

bool === unit // false
bool === unit.value() // true

unit + '' // 'false'
unit + 1 // 1, because false is converted to 0
unit.dispatch(true);
unit + 1 // 2, because true is converted to 1

typeof bool === 'boolean' // true
typeof unit === 'object' // true
typeof unit.value() === 'boolean' // true

// value assignment
bool = true;
unit.dispatch(true);

// value access
console.log(bool) // logs true
console.log(unit.value()) // logs true
// or
unit.subscribe(value => console.log(value)) // logs true, will log future values
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.activejs.dev/activejs/fundamentals/units/boolunit.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
