Programming language

ClearScript. JavaScript's ideas, without its surprises.

ClearScript is a programming language that keeps what is familiar about JavaScript and removes the behaviours that cause bugs: silent type conversion, hoisting, loose equality and prototype chains. Programs compile to WebAssembly.

What it changes

  • No silent type conversion
  • One way to compare values
  • Explicit imports only
  • One built-in toolchain

Who it is for

Many JavaScript bugs come from the language, not the programmer. ClearScript makes those mistakes errors you see before the code runs.

  • JavaScript developers

    Familiar shapes, with a compiler that refuses the code that would have failed at runtime.

  • Teams tired of tool sprawl

    Formatting, linting, testing and running come with the language instead of from five separate packages.

  • Anyone building for the browser or the edge

    Programs compile to WebAssembly, so they run in a browser or any WebAssembly host.

What you get

A language that says no early.

Each decision removes a known source of JavaScript bugs rather than adding a type layer on top.

  • No silent conversion

    Types are never converted behind your back. Adding a number and a string is a compile error, not a surprise string.

  • One way to compare

    A single strict equality operator, so a comparison always means what it says.

  • Explicit imports

    Every name comes from an import. No ambient globals, so dependencies can be read and audited.

  • Errors that explain

    Each error points at the exact place, names the cause and suggests a fix.

  • One toolchain

    Run, format and check with the same command-line tool, plus a REPL for trying things out.

  • Compiles to WebAssembly

    Ship to the browser, the edge or any host that runs WebAssembly.

The rules

Ten rules the compiler enforces.

These are not style guidelines. Code that breaks one does not compile.

  • No coercion

    Types never silently convert. Mixed operations refuse to compile and every conversion is explicit.

  • let and mut only

    Bindings are immutable (let) or mutable (mut) and are scoped to their block. There is no var.

  • No hoisting

    Code runs in the order it is written. Using a name before it is declared is an error.

  • Strict equality

    There is one equality operator and it is strict, so zero never equals false.

  • One nil

    A single null-like value that you must handle. No undefined, and no NaN spreading through results.

  • Traits, not prototypes

    Behaviour comes from explicit, type-checked traits. There is no prototype to modify.

  • Lexical self

    The context of a function is fixed where it is written, not by how it is called.

  • Explicit imports

    No globals. Every symbol comes from an import, so the dependency graph is static.

  • Errors that teach

    Every error has a location, a cause and a suggested fix.

  • One toolchain

    Compiler, formatter, linter, package manager, REPL and editor support come as one tool.

Side by side

The same intent, different guarantees.

Two JavaScript habits that fail at runtime, and what ClearScript does with them.

Type safetyJavaScript
function add(a, b) {
  return a + b;
}
add(5, "3");  // "53" (coerced)
add(5, null); // 5

JavaScript converts the values and carries on.

Type safetyClearScript
fn add(a: num, b: num) -> num {
  a + b
}
add(5, "3");  // compile error
add(5, nil);  // compile error
add(5, 3);    // 8

ClearScript rejects both calls before the program runs.

Questions

Frequently asked.

Is ClearScript JavaScript?

No. It is a separate language with familiar shapes. It is not a superset of JavaScript or a linter for it, so existing JavaScript does not run unchanged.

Where does ClearScript run?

Programs compile to WebAssembly, so they run in a browser or in any host that runs WebAssembly.

How can I try it?

The ClearScript site has an in-browser playground and documentation. Open it from the button at the top of this page.

ClearScript

Write JavaScript-shaped code you can trust.

Try the playground, or talk to us if you want to build on ClearScript.