Global functions
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.
isNaN(x)
ExactReports whether a number is NaN. Compiled as an unordered float comparison, so it agrees with NaN's defining self-inequality.
Returnsboolean — true if x is NaN.
console.log(isNaN(NaN)) // trueisFinite(x)
ExactReports whether a number is neither NaN nor an infinity.
Returnsboolean — true if x is a finite number.
console.log(isFinite(Infinity)) // falseString(x)
ExactCoerces 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.
Returnsstring — The stringified value.
return String(km * 621371 / 1000000) + "mi";Number(x)
ExactCoerces 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.
Returnsnumber — The numeric value, or NaN.
const n = Number(s);
if (Number.isNaN(n)) { throw new TypeError("not a number: " + s); }Boolean(x)
ExactCoerces a value to a boolean using the shared truthiness rules (NaN, "", and 0 are falsy).
Returnsboolean — The truthiness of x.
console.log(e instanceof TypeError, Boolean(e));parseInt(s, radix?)
ExactParses 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.
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)) // 255parseFloat(s)
supportedParses 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.
number — The parsed float, or NaN.
console.log(parseFloat('3.14')) // 3.14
console.log(parseFloat('1e3')) // 1000NaN (global constant)
ExactThe 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.
Returnsnumber — The IEEE-754 NaN value.
const nan: float64 = NaN
console.log(nan !== nan) // true (the defining property of NaN)Infinity (global constant)
ExactThe bare Infinity global (same value as Number.POSITIVE_INFINITY), usable without the Number. prefix; -Infinity is the negative pole.
Returnsnumber — The IEEE-754 positive infinity.
console.log(-Infinity < 0) // true
console.log(Infinity > 1000000) // trueundefined (global constant)
ExactThe undefined global, as a literal value.
Returnsundefined — The undefined value.
globalThis
ExactThe 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 objectencodeURI(s)
ExactPercent-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.
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)decodeURI(s)
supportedDecodes 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.
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)encodeURIComponent(s)
ExactPercent-encodes a single query-string value or path segment, leaving only the unreserved set (letters, digits, -_.!~*'()) unescaped.
Parameters- sstring
- The component to encode.
string — The encoded component.
console.log(encodeURIComponent("hello world")) // hello%20world
console.log(encodeURIComponent("a=b&c=d")) // a%3Db%26c%3DddecodeURIComponent(s)
ExactDecodes a query-string value or path segment, decoding every valid %XX escape unconditionally.
Parameters- sstring
- The component to decode.
string — The decoded component.
console.log(decodeURIComponent("hello%20world")) // hello world
console.log(decodeURIComponent("a%3Db%26c%3Dd")) // a=b&c=datob(s)
ExactBase64 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.
string — The decoded bytes as a string.
console.log(atob("aGVsbG8=")) // hello
console.log(atob(btoa("round trip 123!@#"))) // round trip 123!@#btoa(s)
ExactBase64 encode, =-padded (RFC 4045).
Parameters- sstring
- Bytes to encode.
string — The base64 text.
console.log(btoa("hello")) // aGVsbG8=
console.log(btoa("hi")) // aGk=structuredClone(obj)
Works, with caveatsA 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.
T — An independent deep copy.
const clone = structuredClone(original)
clone.points[0].x = 500
console.log(original.points[0].x) // 0EventEmitter/URL/URLSearchParams/functions/class instances/Promise/any/unknownare rejected at compile time rather than silently aliased (URLmatches Node, which throwsDataCloneError); aMap/Setwith an array/Map/Set key or value element type is also rejected (only scalar/string/object elements clone). A plainArrayBufferis byte-copied, aSharedArrayBufferpasses by reference, and anError(or subtype) copies its kind/message/name.
queueMicrotask(fn)
Works, with caveatsA FIFO of callback closures, run after the current synchronous script and before timers.
Parameters- fn() => void
- Callback to run as a microtask.
void — Nothing.
- 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 caveatsThe Node --expose-gc global.gc() idiom; added to make weak-reference reclamation deterministically observable.
Returnsvoid — Nothing.
- 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 supportedGeneral/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).
any — The evaluated expression's value.
console.log(eval("2 ** 10")) // 1024
const answer: number = eval("6 * 7")
console.log(answer) // 42