# JavaScript

## Links

* [Design Patterns](https://addyosmani.com/resources/essentialjsdesignpatterns/book/#designpatternstructure)
* [Eloquent javascript](https://eloquentjavascript.net/02_program_structure.html)
* [JS the right way](http://jstherightway.org/)

## Cheat sheet

### Objects

```js
const object = {
  a: 'somestring',
  b: 42,
  c: false
}
```

[Object.keys()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) - returns an array with object keys.

```js
Object.keys(object) => ["a", "b", "c"]
```

[Object.values()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values) - returns an array of object values, omit keys.

```js
Object.values(object) => ["somestring", 42, false]
```

[Object.entries()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries) - returns an array with `[key, value]` pairs.

```js
for (let [key, value] of Object.entries(object)) {
  console.log(`${key}: ${value}`)
}

// expected output:
// "a: somestring"
// "b: 42"
// order is not guaranteed
```

[Object.freeze()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) - prevent object mutations.

### console.log() with css styles

```js
console.log('%cyou are awesome :)', 'color: white; font-size: 46px')
```


---

# 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://alexgrischuk.gitbook.io/wiki/coding/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.
