Running ant with no arguments and no piped input opens an interactive Read-Eval-Print Loop (REPL). The REPL is a fast way to experiment with JavaScript, test expressions, explore Ant’s built-in APIs, and debug small snippets without writing a file. Every expression you type is evaluated immediately and the result is printed below it.
Starting the REPL
Ant prints a welcome message and drops you into the prompt:
Welcome to Ant JavaScript v0.1.0
Type .copy [code] to copy, .help for more information.
❯
The ❯ prompt indicates the REPL is ready for input. A dimmed | prompt appears when you are inside a multi-line expression.
Evaluating expressions
Type any JavaScript expression and press Enter. Ant evaluates it and prints the result.
❯ 1 + 1
2
❯ "hello".toUpperCase()
'HELLO'
❯ [1, 2, 3].map(x => x * 2)
[ 2, 4, 6 ]
❯ typeof globalThis
'object'
Non-undefined results are pretty-printed with color highlighting. undefined results are not printed.
If you open a parenthesis, bracket, brace, or template literal without closing it, Ant switches to multi-line mode and shows a continuation prompt. Press Enter on an empty line to submit the buffered input.
❯ function add(a, b) {
| return a + b;
| }
undefined
❯ add(3, 4)
7
The REPL tracks bracket depth, string context, and template literals to determine whether input is complete before evaluating.
Special variables
The REPL exposes two special variables that are updated after each evaluation:
| Variable | Value |
|---|
_ | The result of the last evaluated expression |
_error | The last uncaught error |
❯ Math.PI * 2
6.283185307179586
❯ _
6.283185307179586
REPL commands
Commands start with a . and are available at the top-level prompt only (not inside multi-line input).
| Command | Description |
|---|
.help | List all commands and keybindings |
.exit | Exit the REPL |
.clear | Clear the screen |
.history | Show command history |
.load <file> | Load a JavaScript file into the current session |
.save <file> | Save all evaluated commands in this session to a file |
.stats | Show memory statistics |
.copy [expr] | Evaluate an expression and copy its value to the clipboard |
Keybindings
| Key | Action |
|---|
| Ctrl+D | Exit (EOF) |
| Ctrl+C | Abort current expression; press twice to exit |
| Up / Down | Navigate history |
| Left / Right | Move backward/forward one character |
| Home / End | Jump to start/end of line |
| Backspace | Delete character backward |
| Delete | Delete character under cursor |
| Enter | Submit input |
Syntax highlighting
The REPL highlights your input as you type, using the same syntax rules as Ant’s engine. Keywords, strings, numbers, and identifiers are colored distinctly. Multi-line buffers are highlighted based on the accumulated input so far, keeping the visual context consistent as you type.
Loading an existing file
Use .load to bring a script file into your running REPL session without leaving the prompt:
All declarations from the file become available in your session. This is useful for loading helper functions you want to call interactively.
Saving your session
Use .save to write every expression you evaluated in the current session to a file:
❯ .save session.js
Session saved to session.js
The REPL stores history across sessions. Your previous commands are available with the Up arrow the next time you open the REPL.