> For the complete documentation index, see [llms.txt](https://web-dev-guide.wishtack.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://web-dev-guide.wishtack.io/ecmascript/compatibility.md).

# Compatibility

How can we use the latest ECMAScript features and still be compatible with most browsers?

<https://kangax.github.io/compat-table/es6/>

{% embed url="<https://kangax.github.io/compat-table/es6/>" %}

## Transpilation

ECMAScript 5.1 is for modern ECMAScript what assembly is for C++.

We need a transpiler:

* Babel: <https://babeljs.io/>​
* TypeScript: <https://www.typescriptlang.org/>​

But this will not be enough as transpilers will only convert syntactic features but not new browser APIs and methods.

## Polyfills

We need to compensate the lack of some objects, functions or methods `customElements`, `fetch`, `Array.filter` on some browsers.

In order to fill the gap, we will use polyfill libraries. These libraries detect missing features and compensate them with **JavaScript implementations**.

Example:

```javascript
if (Array.prototype.first == null) {
    Array.prototype.first = function () {
        return this[0];
    };
}
​
const valueList = [1, 2, 3];
​
console.log(valueList.first()); // 1
```

One of the most famous polyfill libraries is core-js <https://github.com/zloirock/core-js>.

Or you can use a polyfill service like <https://polyfill.io>.


---

# 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://web-dev-guide.wishtack.io/ecmascript/compatibility.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.
