> For the complete documentation index, see [llms.txt](https://david-m-neuman.gitbook.io/brain-food/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://david-m-neuman.gitbook.io/brain-food/pages/docs/book-notes/eloquent-javascript.md).

# Eloquent Javascript - Marijn Haverbeke

![](https://eloquentjavascript.net/img/cover.jpg)

## Chapter 1: Values, Types, and Operators

> Bits are any kind of two-valued things, usually described as zeros and ones. Inside the computer, they take forms such as a high or low electrical charge, a strong or weak signal, or a shiny or dull spot on the surface of a CD. Any piece of discrete information can be reduced to a sequence of zeros and ones and thus represented in bits.

Modern computers have more than 30 billion bits in its working memory. We separate them into chunks - called **values** - so that we can represent the bits without getting confused.

JavaScript uses 64 bits. This translates into 2^64 different numbers (18 quintillion). Meaning, we can use 64-bit chunks freely without worrying about memory overflow.

## Chaper 2: Program Structure

An **expression** is a fragment of code that produces a value. A **statement** contains multiple expressions to produce a program. A program, therefore, is a list of statements. Statements are only useful when they change the the state of the world or the internal state of the machine in a way that affects subsequent statements.

**Chessboard Challenge**

The below program outputs a `size` x `size` chessboard. The sum of the inner and outer loop indices reflects the current position in the two-dimensional grid. The logic here is that if the modulus (`%`) of the current position is even we output a space. Otherwise, we output a `#`.

```javascript
function createChessboard(size = 8) {
  let board = ''

  for (let i = 0; i < size; i++) {
    board += '|'
    for (let j = 0; j < size; j++) {
      if ((j + i) % 2 === 0) {
        board += ' '
      } else {
        board += '#'
      }
    }
    board += '|'
    board += '\n'
  }

  console.log(board)
}

createChessboard()

/* Output:

|# # # # |
| # # # #|
|# # # # |
| # # # #|
|# # # # |
| # # # #|
|# # # # |
*/
```


---

# 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:

```
GET https://david-m-neuman.gitbook.io/brain-food/pages/docs/book-notes/eloquent-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
