Skip to main content
The js utility is a command-line JavaScript interpreter that implements the ECMAScript specification. It provides both a REPL (Read-Eval-Print Loop) for interactive JavaScript execution and script execution capabilities.

Usage

Basic syntax

Interactive REPL

Launch the REPL by running js without arguments:
The REPL provides:
  • Line editing with syntax highlighting
  • Multi-line input support
  • Command history (saved to ~/.js-history)
  • Auto-completion for variables and properties

Execute scripts

Evaluate inline code

Command-line options

Script execution options

Debugging options

Display options

Test262 support

The --use-test262-global option enables the Test262 global object, which provides functions like $262.createRealm() and $262.evalScript() required by the official ECMAScript Test262 suite.

REPL commands

The REPL provides several built-in commands:

exit([code])

Exit the REPL with an optional exit code (defaults to 0).

help()

Display available REPL commands.
Pretty-print a JavaScript value.

loadINI(file)

Load an INI file and return its contents as a JavaScript object.

loadJSON(file)

Load and parse a JSON file.

save(file)

Save REPL input history to a file.

Special variables

_

Access the result of the last expression:
Assigning to _ disables the automatic last value tracking. You’ll need to restart the REPL to re-enable it.

global

Reference to the global object:

Examples

Running a JavaScript file

Executing code with modules

Debugging bytecode

Testing with raw output

Interactive exploration

Features

Syntax highlighting

The REPL automatically highlights JavaScript syntax:
  • Keywords in blue
  • Strings in green
  • Numbers in magenta
  • Control keywords in cyan
  • Identifiers in white
Disable syntax highlighting with the --no-syntax-highlight option if you’re piping output or prefer plain text.

Error reporting

Detailed error messages with source location:

Multi-line input

The REPL automatically handles multi-line expressions:

Promise tracking

The interpreter warns about unhandled promise rejections:

Implementation details

Global objects

The js utility provides two global object types:
  1. ReplObject - Used in REPL mode, includes REPL-specific functions
  2. ScriptObject - Used in script mode, minimal global environment

JavaScript engine

The utility uses LibJS, Ladybird’s JavaScript engine:
  • Full ECMAScript support
  • Bytecode compilation and interpretation
  • Garbage collection
  • ES modules support

Console object

Full console API support:

Platform support

Windows: REPL functionality is not supported on Windows due to LibLine dependency. Script execution works normally.
Linux/macOS: Full support including REPL with line editing and history.
  • test262-runner - Automated Test262 test suite runner
  • wasm - WebAssembly runtime with JavaScript integration

Source code

Source file: Utilities/js.cpp