# JavaScript

| Type                     | MDN                                                                                                         |
| ------------------------ | ----------------------------------------------------------------------------------------------------------- |
| Array                    | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)               |
| Date                     | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)                |
| Object                   | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)              |
| String                   | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)              |
| JSON                     | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)                |
| Set                      | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)                 |
| RegExp                   | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)              |
| Destructuring Assignment | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) |
| const                    | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const)                   |
| let                      | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let)                     |
| export                   | [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)                  |

### Variable declarations

`var`

* function scoped
* can be redeclared and updated
* hoisted and initialized with `undefined` as a value

`let`

* block scoped
* declaring in a for loop, inside an if or in a plain block is not going to let the variable "escape" the block
* only use `let` to reassign the variable
* while `let` and `const` are hoisted but not initialized

`const`

* immutable
* block-scoped
* default to `const`

### Array

* <https://sdras.github.io/array-explorer/>
* <https://flaviocopes.com/javascript-array/>

### Object

* <https://sdras.github.io/object-explorer/>
* <https://codepen.io/thonly/pen/JOdwKM>

### Promises

When you go to a restaurant, the hostess gives you a buzzer for your table. When the table is ready, the buzzer buzzes. You respond by sitting at the table.

The buzzer is a promise. It buzzes when the promise resolves, or is ready. The buzz is your handler.

```javascript
var buzzer = new Promise();

fetchTableAsync(hostess => {
    var table = hostess.prepareTable();
    hostess.informServer();
    buzzer.resolve(table);
});

buzzer.then(table => me.sitAtTable(table));
```

* <https://github.com/wbinnssmith/awesome-promises>

### Currying

Currying is a process to reduce functions of more than one argument to functions of one argument with the help of lambda calculus.

```javascript
multiply = (n, m) => (n * m)
multiply(3, 4) === 12 // true

curryedMultiply = (n) => ( (m) => multiply(n, m) )
triple = curryedMultiply(3)
triple(4) === 12 // true
```

* <https://blog.benestudio.co/currying-in-javascript-es6-540d2ad09400>


---

# Agent Instructions: 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://docs.lovincyrus.com/notes/undefined.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.
