# JavaScript language

> Which ECMAScript edition and proposals Elide runs (Temporal, ShadowRealm, AsyncContext, `using`, Float16Array), and the non-standard globals `print`, `printErr`, `gc`, `Operators`, `Process` and `XMLHttpRequest`.

Elide runs ECMAScript 2025 and the newer features below, with no flag. The project's
[`javascript.ecma`](https://elide.help/docs/elide-pkl-reference#javascript) setting is informational and does not change them.

## Language features

| Feature | Status |
| --- | --- |
| ECMAScript 2025: iterator helpers, `Set` methods, `Promise.try`, `RegExp.escape`, import attributes, regexp modifiers, duplicate named groups | Supported |
| `using`, `await using`, `DisposableStack`, `AsyncDisposableStack` | Supported |
| `Float16Array`, `Math.f16round` | Supported |
| `Temporal` | Supported |
| `ShadowRealm` | Supported |
| `AsyncContext.Variable`, `AsyncContext.Snapshot` | Supported; values follow `await`, `.then()`, timers, `setImmediate`, `process.nextTick` and `queueMicrotask` |
| `Error.isError`, `Math.sumPrecise`, `Iterator.concat`, `Map.prototype.getOrInsert` | Supported |
| `Uint8Array.fromBase64`, `toBase64`, `fromHex`, `toHex` | Supported |
| JSON.parse source text access (`context.source` in the reviver) | Supported |
| Decorators | Standard decorators; see [TypeScript and modules](https://elide.help/docs/typescript-and-modules#typescript-syntax) |
| `Intl` | Supported |

```js
// modern.mjs
{
  using file = { [Symbol.dispose]() { console.log("closed"); } };
  console.log("open");
}

const due = Temporal.PlainDate.from("2026-10-11").add({ days: 30 });
console.log(due.toString(), due.dayOfWeek);

const request = new AsyncContext.Variable();
await request.run("req-1", async () => {
  await null;
  console.log("request", request.get());
});

const realm = new ShadowRealm();
console.log(realm.evaluate("typeof process"));

console.log(new Float16Array([1.337])[0]);
console.log([1, 2, 3].values().map((x) => x * 2).toArray().join());
```

```bash
elide modern.mjs
```

```text
open
closed
2026-11-10 2
request req-1
undefined
1.3369140625
2,4,6
```

A `ShadowRealm` has the ECMAScript built-ins, `console` and `require`, but no `process`, `fetch` or `Buffer`.

## Non-standard globals

| Global | Behavior |
| --- | --- |
| `print(...values)` | Writes the values to stdout, separated by spaces. Objects print as `[object Object]`. |
| `printErr(...values)` | The same, to stderr. |
| `gc()` | Defined only when the program receives `--expose-gc`: `elide app.mjs -- --expose-gc`. Requests a garbage collection. |
| `Operators(table)` | Operator overloading: returns a base class whose subclasses use the functions in `table` for `+`, `-`, `<` and the other operators. |
| `Process` | The class of `process`; `new Process()` throws `TypeError: Creating Process instances is not allowed`. |
| `XMLHttpRequest` | Not supported. The constructor exists, but every request fails: `onerror` fires and `status` is `0`. Use `fetch`. |

```js
const Vector = Operators({ "+"(a, b) { return new Vec(a.x + b.x); } });
class Vec extends Vector {
  constructor(x) { super(); this.x = x; }
}
console.log((new Vec(1) + new Vec(2)).x); // 3
```

## Samples

- [Dates with Temporal](https://elide.help/docs/code-samples#dates-with-temporal)

## See also

- [TypeScript and modules](https://elide.help/docs/typescript-and-modules)
- [API overview](https://elide.help/docs/api-overview)
- [Compatibility matrix](https://elide.help/docs/compatibility)
