Skip to main content
When running scripts with the qjs executable, several global functions and variables are automatically available without requiring module imports.
These globals are added by the qjs executable and are not available when embedding QuickJS in other applications unless explicitly configured.

Global Variables

argv0

string
The full path to the executable that is running the script.

scriptArgs

string[]
Command line arguments passed to the script. The first element is always the script filename.
string
Returns a string in the format quickjs-ng/<version>.

Global Functions

Prints the arguments separated by spaces with a trailing newline.
any
Any number of arguments to print. Non-string values are converted to strings.

console.log(...args)

Alias for print(). Behaves identically to print().
any
Any number of arguments to print.
Unlike browser or Node.js environments, console.log in QuickJS-ng is simply an alias for print() and does not support advanced formatting or object inspection.

gc()

Manually triggers garbage collection.
undefined
This function does not return a value.
The garbage collector runs automatically when needed. Manual invocation is useful in specific scenarios:
  • Memory-constrained environments - Force cleanup before starting memory-intensive operations
  • Testing and benchmarking - Ensure consistent memory state between test runs
  • Long-running scripts - Periodically clean up in scripts that run for extended periods
In most cases, you should rely on automatic garbage collection.
gc() is a shorthand for std.gc() from the qjs:std module.

Comparison with Other Environments

QuickJS-ng globals differ from Node.js:
QuickJS-ng globals differ from browsers:

Example: Command-Line Script

Next Steps

std Module

Explore the standard library module

os Module

Learn about OS-level functions

Overview

Return to stdlib overview