API reference

Global functions

20/21Coverage17/21Strict (zero caveats)

JavaScript's language-level globals — numeric parsing, type coercion, URI/base64 codecs, and deep cloning — compiled to plain C-stdlib calls with no runtime engine. globalThis.X reads the global X, and globalThis as a value is the global object, holding the builtins and whatever the program sets on it. Dynamic eval is out of scope — it needs the (unstarted) embedded engine, though a compile-time-constant eval("<expression>") does route through this compiler's own parser. Malformed input is rejected where JS rejects it — decodeURI/decodeURIComponent throw URIError and atob enforces forgiving-base64 with QuotaExceededError.

Exact Works, with caveats Not supported

isNaN(x)

Exact
isNaN(x: number): boolean

Reports whether a number is NaN. Compiled as an unordered float comparison, so it agrees with NaN's defining self-inequality.

Returns

boolean — true if x is NaN.

console.log(isNaN(NaN))            // true
See it in a full example →

isFinite(x)

Exact
isFinite(x: number): boolean

Reports whether a number is neither NaN nor an infinity.

Returns

boolean — true if x is a finite number.

console.log(isFinite(Infinity))    // false
See it in a full example →

String(x)

Exact
String(x: any): string

Coerces a value to its string form. Routes through the template-literal renderer; an any input dispatches on its runtime tag. `String()` with no argument is `""` and `String(undefined)` is `"undefined"`, matching JS.

Returns

string — The stringified value.

return String(km * 621371 / 1000000) + "mi";
See it in a full example →

Number(x)

Exact
Number(x: any): number

Coerces a value to a number using JS ToNumber semantics: a whole-string parse ("12px" is NaN, unlike parseFloat), ""/whitespace is 0, "0x10" is 16, boolean is 0/1, null is 0; a numeric input passes through unchanged (an exact i64 stays i64). Only the exact word "Infinity" (optionally signed) is Infinity — C's "inf"/case variants are NaN, matching real JS.

Returns

number — The numeric value, or NaN.

const n = Number(s);
if (Number.isNaN(n)) { throw new TypeError("not a number: " + s); }
See it in a full example →

Boolean(x)

Exact
Boolean(x: any): boolean

Coerces a value to a boolean using the shared truthiness rules (NaN, "", and 0 are falsy).

Returns

boolean — The truthiness of x.

console.log(e instanceof TypeError, Boolean(e));
See it in a full example →

parseInt(s, radix?)

Exact
parseInt(s: string, radix?: number): number

Parses a leading integer out of a string, stopping at the first non-digit. A no-digits input returns a real NaN (endptr-checked, double result). With radix omitted, auto-detects base 16 for a "0x"/"0X" prefix (parseInt("0xFF") is 255) and base 10 otherwise — no octal auto-detect, so "077" is 77.

Parameters
sstring
String to parse.
radixnumber
Base 2–36; defaults to 10, or 16 for a "0x" prefix.
Returns

number — The parsed integer, or NaN.

console.log(parseInt('3abc'))      // 3   (stops at first non-digit)
console.log(parseInt('0xFF'))      // 255 (auto-detected hex)
console.log(parseInt('FF', 16))    // 255
See it in a full example →

parseFloat(s)

supported
parseFloat(s: string): number

Parses a leading floating-point number out of a string. A "0x" hex prefix reads only its leading 0 → 0 (real parseFloat, unlike Number("0x10") → 16). A no-conversion input returns a real NaN; only the exact word "Infinity" parses to Infinity ("inf" is NaN).

Parameters
sstring
String to parse.
Returns

number — The parsed float, or NaN.

console.log(parseFloat('3.14'))    // 3.14
console.log(parseFloat('1e3'))     // 1000
See it in a full example →

NaN (global constant)

Exact
const NaN: number

The bare NaN global (same value as Number.NaN), usable without the Number. prefix. NaN != x and !== x comparisons are correct — compiled as unordered fcmp une, so NaN !== NaN is true as in JS.

Returns

number — The IEEE-754 NaN value.

const nan: float64 = NaN
console.log(nan !== nan)           // true  (the defining property of NaN)
See it in a full example →

Infinity (global constant)

Exact
const Infinity: number

The bare Infinity global (same value as Number.POSITIVE_INFINITY), usable without the Number. prefix; -Infinity is the negative pole.

Returns

number — The IEEE-754 positive infinity.

console.log(-Infinity < 0)         // true
console.log(Infinity > 1000000)    // true
See it in a full example →

undefined (global constant)

Exact
const undefined

The undefined global, as a literal value.

Returns

undefined — The undefined value.

globalThis

Exact
globalThis

The global object. globalThis.X for a declared global (a builtin, or a declare global var) is that global, including nested and call forms like globalThis.JSON.stringify(...) and globalThis.setTimeout(...). As a value it is one object holding the builtins as its properties and whatever the program sets on it — globalThis.x = …, computed keys, passing it around. A module's top-level bindings are not on it, as in an ES module.

(globalThis as any).appVersion = '1.2.3'
const g: any = globalThis
console.log(g.appVersion, typeof globalThis) // 1.2.3 object

encodeURI(s)

Exact
encodeURI(s: string): string

Percent-encodes a whole URI, leaving the unreserved and reserved (;/?:@&=+$,#) character sets unescaped so the URI's own structure survives.

Parameters
sstring
The URI to encode.
Returns

string — The encoded URI.

console.log(encodeURI("http://example.com/path?a=1&b=2 space"))
// http://example.com/path?a=1&b=2%20space (only the space got escaped)
See it in a full example →

decodeURI(s)

supported
decodeURI(s: string): string

Decodes a whole URI; a malformed escape throws a URIError as in JS. Does not decode a %XX escape representing a reserved character (leaves it as literal %XX text) — the one real behavioral difference from decodeURIComponent.

Parameters
sstring
The URI to decode.
Returns

string — The decoded URI.

console.log(decodeURI("http://example.com/path%3Fa=1&b=2%20space"))
// http://example.com/path%3Fa=1&b=2 space (%3F stays literal — it's '?', reserved)
See it in a full example →

encodeURIComponent(s)

Exact
encodeURIComponent(s: string): string

Percent-encodes a single query-string value or path segment, leaving only the unreserved set (letters, digits, -_.!~*'()) unescaped.

Parameters
sstring
The component to encode.
Returns

string — The encoded component.

console.log(encodeURIComponent("hello world"))         // hello%20world
console.log(encodeURIComponent("a=b&c=d"))             // a%3Db%26c%3Dd
See it in a full example →

decodeURIComponent(s)

Exact
decodeURIComponent(s: string): string

Decodes a query-string value or path segment, decoding every valid %XX escape unconditionally.

Parameters
sstring
The component to decode.
Returns

string — The decoded component.

console.log(decodeURIComponent("hello%20world"))       // hello world
console.log(decodeURIComponent("a%3Db%26c%3Dd"))       // a=b&c=d
See it in a full example →

atob(s)

Exact
atob(s: string): string

Base64 decode implementing WHATWG forgiving-base64: ASCII whitespace is stripped, a missing-padding trailing group still decodes, a remaining length ≡ 1 (mod 4) throws InvalidCharacterError, and an interior or excess `=` (accepted only as trailing padding) throws too. Operates byte-for-byte on the input string (this compiler's strings are already plain byte sequences — no separate "binary string" type needed).

Parameters
sstring
Base64 text to decode.
Returns

string — The decoded bytes as a string.

console.log(atob("aGVsbG8="))                   // hello
console.log(atob(btoa("round trip 123!@#")))    // round trip 123!@#
See it in a full example →

btoa(s)

Exact
btoa(s: string): string

Base64 encode, =-padded (RFC 4045).

Parameters
sstring
Bytes to encode.
Returns

string — The base64 text.

console.log(btoa("hello"))                      // aGVsbG8=
console.log(btoa("hi"))                         // aGk=
See it in a full example →

structuredClone(obj)

Works, with caveats
structuredClone<T>(obj: T): T

A real recursive deep copy, dispatched entirely on the argument's static type: arrays (incl. nested and TypedArrays), plain objects, and Maps/Sets recurse into freshly allocated storage, cloning every entry deeply; scalars pass through as value types. The result is fully independent of the original.

Parameters
objT
The value to deep-copy.
Returns

T — An independent deep copy.

const clone = structuredClone(original)
clone.points[0].x = 500
console.log(original.points[0].x) // 0
See it in a full example →
⚠ Differences from standard
  • EventEmitter/URL/URLSearchParams/functions/class instances/Promise/any/unknown are rejected at compile time rather than silently aliased (URL matches Node, which throws DataCloneError); a Map/Set with an array/Map/Set key or value element type is also rejected (only scalar/string/object elements clone). A plain ArrayBuffer is byte-copied, a SharedArrayBuffer passes by reference, and an Error (or subtype) copies its kind/message/name.

queueMicrotask(fn)

Works, with caveats
queueMicrotask(fn: () => void): void

A FIFO of callback closures, run after the current synchronous script and before timers.

Parameters
fn() => void
Callback to run as a microtask.
Returns

void — Nothing.

⚠ Differences from standard
  • Drained at the reachable checkpoints (end of the top-level script, each scheduler step); a program with neither timers nor async tasks drains once at exit.

gc()

Works, with caveats
gc(): void

The Node --expose-gc global.gc() idiom; added to make weak-reference reclamation deterministically observable.

Returns

void — Nothing.

⚠ Differences from standard
  • A no-op under -mm=manual (the default) — nothing is ever collected; only meaningful under -mm=gc, where it forces a full Boehm collection.

eval(s)

Not supported
eval(s: string): any

General/dynamic eval is unimplemented (it needs the opt-in embedded engine, not started). A narrow static subset does work: a compile-time-constant eval("<expression>") is compiled in place through this compiler's own parser and codegen, no engine. A dynamic string, a statement/declaration, or a reference to a top-level binding is a clean compile error, never a runtime throw.

Parameters
sstring
A compile-time-constant expression string (static subset only).
Returns

any — The evaluated expression's value.

console.log(eval("2 ** 10"))          // 1024
const answer: number = eval("6 * 7")
console.log(answer)                    // 42
See it in a full example →