js(1) - SerenityOS man pages

Name

js - evaluate JavaScript

Synopsis

$ js [options...] [script.js]

Description

js evaluates JavaScript programs using the LibJS engine. If you pass it a path to a script file, it will execute that script. Otherwise, it enters the Read-Eval-Print-Loop (REPL) mode, where it interactively reads pieces (usually, single lines) of code from standard input, evaluates them in one shared interpreter context, and prints back their results. This mode is useful for quickly experimenting with LibJS.

Run help() in REPL mode to see its available built-in functions.

Options

Examples

Here's how you execute a script:

$ js ~/Source/js/type-play.js

And here's an example of an interactive REPL session:

$ js
> function log_sum(a, b) {
>     console.log(a + b)
> }
undefined
> log_sum(35, 42)
77
undefined

See also