The Language Guide

Eighteen chapters covering the whole core language. Every code sample was executed on both backends (tree-walking interpreter and bytecode VM); the output shown beneath each example is the real, verified output.

Coming from JavaScript, C++ or C#? The Language Bridges map what you already know onto JaiScript, one page per language, and point back into these chapters. Code moving from a C++ library (Cereal, sol2, pybind11 and others) starts in the Code Migrations.

Follow along in a terminal. Drop a sample into try.jai, run jaiscript try.jai with the standalone runner, and you get what the page shows, with one small convention: the == result: line, explained in Hello & Basics along with the two-minute setup.

One thing to know before chapter 1: the static checker is always on, and strict. A typed mistake the checker can see (a string into an int, a call with the wrong number of arguments, an undeclared name) fails the load, before a single statement runs. Chapter 2 draws the line between those and the mistakes that still wait for run time; Chapter 13 collects the whole story, escape hatches included.

Which of these rules are settled for 1.0, and which may still change in a 0.x release, is on the Stability page.

  1. Hello & Basics

    Run a script from C++, meet the values and literals, learn print/format, and see how the last expression becomes the result.

  2. The Type Ladder: typed, auto, var

    Three rungs of typing strictness (int enforced, auto inferred then locked, var dynamic), the one conversion table every typed slot runs, and cast<T>, the explicit boundary.

  3. Value Semantics & References

    If you read only one chapter, read this one. JaiScript copies by default, everywhere. Here are the escape hatches (& parameters, references, shared_ptr) and what each one costs.

  4. Operators & Arithmetic

    The full C++ operator set with checked overflow, no undefined behavior, char promotion, a contractual evaluation order, and operator overloading on script classes.

  5. Control Flow

    if/while/for, range-for, switch with break-by-default, try/catch/throw, and the execution budget a runaway script cannot catch its way past.

  6. Functions & Lambdas

    Every C++ way of spelling a function, default arguments, lambdas with real capture lists, closures that outlive their frame, and functions as values.

  7. Classes

    Fields in declaration order, constructor overloading and delegation, inheritance with explicit override, statics, access control, and hot reload with instance migration.

  8. Coroutines

    coroutine/yield with handles advanced by next(): drivable by range-for, storable in fields, alive across separate executes.

  9. Containers & Strings

    Arrays, ordered maps, typed containers, the full string method set, template strings with format specs, and byte-level string reads.

  10. Modules: include vs import

    include runs every time; import caches with timestamp awareness. Hot reload falls straight out of that split.

  11. Enums, Namespaces, Destructuring & Friends

    The smaller conveniences: enums, namespaces, destructuring, the ternary operator, and null-safe access.

  12. Reflection: reflect::

    Ask, act, and navigate by name: fields, methods, get/set/invoke, spawn-by-name. Live queries that survive hot reload, enforcing exactly what direct syntax enforces.

  13. Types That Fail Early: strict checking

    What fails at load and what waits for run time, how to read a diagnostic, the promise that a clean program is never rejected, cast<T> as the explicit boundary, extern, and the [[warn_mode]] / [[strict_mode]] attributes.

  14. Time: Clocks, Stopwatches & Dates

    The time:: namespace: monotonic and wall clocks, value-type stopwatches, validated calendar dates in UTC or local time, templates with format specs, and a clock a host can replace.

  15. Math: Vectors & Colors

    The vec2, vec3, vec4, ivec2, ivec3 and color value types, their operators, the component-wise and geometry libraries, perceptual color mixing, and packed vector arrays.

  16. Parallel Loops

    parallel_for, parallel_transform and parallel_reduce: what a parallel body may and may not do, writes through the loop variables, constructing objects, C++ calls, and reductions that match the serial result at every worker count.

  17. The web:: Library

    HTML escaping, RFC 3986 and form percent-encoding, query strings and URLs as pure functions over strings: the opt-in library a web host registers.

  18. Random Numbers & Crypto

    The random type: a generator you own, seeded streams that replay bit for bit on every platform, copies and save files for rollback, and draws in parallel loops; then crypto:: for secrets: secure random bytes, SHA-2, HMAC and PHP-compatible bcrypt passwords.