> For the complete documentation index, see [llms.txt](https://cs.brash.ca/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cs.brash.ca/unit-2/variables/booleans.md).

# Booleans

By now you probably know what a [boolean value](https://en.wikipedia.org/wiki/Boolean_data_type) is and you may have heard about [boolean algebra](https://en.wikipedia.org/wiki/Boolean_algebra) or [George Boole](https://en.wikipedia.org/wiki/George_Boole). Together, they are the bread and butter that makes programming work.\
\
We can compare two or more values, utilize a boolean for situations with only two states, or combine values using boolean algebra in order to control our code.

In Javascript, anything with a value is considered to be true (see [truthiness](/unit-2/variables/booleans/truthiness.md)). We can use [comparison operators](/unit-2/variables/numbers.md#comparison) to return a `true` or `false` value. For example:  `(10 < 6)   // false`. \
Strongly typed languages such as C++ and Java have a boolean primitive type. JS also has a boolean type but it is loosely (or dynamically) typed, so it can take on other values as well.

Later in our programming adventure, we will even create our own functions that return a boolean value in order to state if something happened or not.

## Boolean Logic

You may have seen boolean logic for [logic gates](/unit-1/binary-and-logic/logic-gates.md). This same process can be applied to boolean values in code.

| Operator | Symbol      | Example(s)                                                                               |   |                                            |   |                            |
| -------- | ----------- | ---------------------------------------------------------------------------------------- | - | ------------------------------------------ | - | -------------------------- |
| Not      | !           | `!(4 < 10)` = false                                                                      |   |                                            |   |                            |
| And      | &&          | <p><code>(true && false)</code> = false</p><p><code>(3 < 5 && 7 > 1)</code> = true</p>   |   |                                            |   |                            |
| Or       | \|\|        | <p><code>(true                                                                           |   | false)</code> = true</p><p><code>(5 > 10   |   | 1 == 1)</code> true</p>    |
| Nand     | !(x && y)   | <p><code>!(true && false)</code> = true</p><p><code>!(3 < 5 && 7 > 1)</code> = false</p> |   |                                            |   |                            |
| Nor      | !(x \|\| y) | <p><code>!(true                                                                          |   | false)</code> = false</p><p><code>!(5 > 10 |   | 1 == 1)</code> = false</p> |


---

# 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://cs.brash.ca/unit-2/variables/booleans.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.
