Skip to main content
Arc provides a standard set of global objects and functions that match the ECMAScript specification, with some BEAM-specific additions.

Global object structure

The global object in Arc contains all standard ECMAScript built-ins plus the Arc namespace for BEAM-specific functionality.

Standard globals

Arc implements standard ECMAScript global properties and functions:

Value properties

  • undefined
  • NaN
  • Infinity
  • globalThis

Function properties

  • parseInt()
  • parseFloat()
  • isNaN()
  • isFinite()
  • eval()

Constructor functions

  • Object
  • Function
  • Array
  • String
  • Number
  • Boolean
  • Symbol
  • Promise
  • Map / Set
  • WeakMap / WeakSet
  • RegExp
  • Error types

Namespaced objects

  • Math
  • JSON
  • Arc (BEAM-specific)

globalThis

The globalThis property provides access to the global object in any environment. This is the standard ECMAScript way to access the global scope.
// All of these refer to the same object
globalThis.Array === Array;  // true
globalThis.Math === Math;    // true
globalThis.Arc === Arc;      // true

// Adding a global property
globalThis.myGlobal = 'value';
Arc.log(myGlobal);  // 'value'
globalThis is the recommended way to access the global object in portable code, as it works consistently across all JavaScript environments.

Global functions

parseInt()

Parses a string argument and returns an integer of the specified radix.
string
string
required
The value to parse. Leading whitespace is ignored.
radix
number
An integer between 2 and 36 representing the base. If omitted or 0, base 10 is assumed (or base 16 if the string starts with 0x).
Returns: number - The parsed integer, or NaN if the first non-whitespace character cannot be converted.
parseInt('42');        // 42
parseInt('  42  ');    // 42
parseInt('0xFF');      // 255
parseInt('101', 2);    // 5 (binary)
parseInt('42px');      // 42
parseInt('abc');       // NaN

parseFloat()

Parses a string argument and returns a floating-point number.
string
string
required
The value to parse. Leading whitespace is ignored.
Returns: number - The parsed floating-point number, or NaN if the first non-whitespace character cannot be converted.
parseFloat('3.14');      // 3.14
parseFloat('  2.5  ');   // 2.5
parseFloat('2.5em');     // 2.5
parseFloat('abc');       // NaN

isNaN()

Determines whether a value is NaN after coercing it to a number.
value
any
required
The value to test. Non-number values are coerced to numbers before testing.
Returns: boolean - true if the value is NaN after coercion, false otherwise.
isNaN(NaN);        // true
isNaN('hello');    // true (coerces to NaN)
isNaN('42');       // false (coerces to 42)
isNaN(undefined);  // true (coerces to NaN)
isNaN({});         // true (coerces to NaN)
isNaN() coerces its argument to a number before testing. Use Number.isNaN() for a more reliable check that doesn’t perform coercion.

isFinite()

Determines whether a value is a finite number after coercing it to a number.
value
any
required
The value to test. Non-number values are coerced to numbers before testing.
Returns: boolean - true if the value is a finite number after coercion, false otherwise.
isFinite(42);         // true
isFinite(Infinity);   // false
isFinite(-Infinity);  // false
isFinite(NaN);        // false
isFinite('42');       // true (coerces to 42)
isFinite('hello');    // false (coerces to NaN)

eval()

Evaluates JavaScript code represented as a string.
code
string
required
A string representing JavaScript code to evaluate.
Returns: The completion value of evaluating the given code. If the code is not a string, returns the argument unchanged.
eval('2 + 2');              // 4
eval('var x = 10; x * 2');  // 20

const code = 'Array.isArray([1, 2, 3])';
eval(code);                 // true
Using eval() can be dangerous if used with untrusted input. It executes arbitrary code with the privileges of the caller. Avoid using eval() when possible.

URI handling functions

Arc provides standard URI encoding and decoding functions:

encodeURI()

Encodes a URI by escaping special characters, except those that are valid in URIs.
encodeURI('https://example.com/path?q=hello world');
// 'https://example.com/path?q=hello%20world'

decodeURI()

Decodes a URI previously created by encodeURI() or similar.
decodeURI('https://example.com/path?q=hello%20world');
// 'https://example.com/path?q=hello world'

encodeURIComponent()

Encodes a URI component by escaping all special characters.
encodeURIComponent('hello world?');
// 'hello%20world%3F'

decodeURIComponent()

Decodes a URI component previously created by encodeURIComponent() or similar.
decodeURIComponent('hello%20world%3F');
// 'hello world?'

Legacy functions

escape() / unescape()

Deprecated. Use encodeURIComponent() and decodeURIComponent() instead.
Arc includes escape() and unescape() for compatibility with legacy code, but these functions are deprecated and should not be used in new code.

Arc namespace

The Arc global namespace provides BEAM-specific concurrency and process management functions:
Arc.spawn()     // Spawn a new BEAM process
Arc.send()      // Send a message to a process
Arc.receive()   // Receive a message
Arc.self()      // Get current process ID
Arc.log()       // Print to stdout
Arc.sleep()     // Sleep for milliseconds
Arc.peek()      // Inspect promise state (non-standard)
See the Arc namespace reference for detailed documentation.

Differences from browser environments

Arc does not provide the browser console object. Use Arc.log() instead for logging output.
Arc is a server-side runtime and does not include DOM APIs like document, window, setTimeout, or fetch.
Traditional timer functions (setTimeout, setInterval) are not available. Use Arc.sleep() for delays in spawned processes.
Arc currently executes single-file scripts. ES modules (import/export) and CommonJS (require) are not yet implemented.

Global object extensibility

You can add properties to the global object just like in standard JavaScript:
// Add a global variable
globalThis.APP_VERSION = '1.0.0';

// Add a global function
globalThis.greet = function(name) {
  Arc.log('Hello,', name);
};

// Use them anywhere
greet('Arc');  // Hello, Arc
Arc.log(APP_VERSION);  // 1.0.0
For better code organization, consider using the module pattern with closures instead of polluting the global namespace.

Build docs developers (and LLMs) love