<!-- https://tinyscript.tinyactors.dev/reference/statements/ -->
# Statements and declarations · Reference

Kind: reference. For: [Script author](https://tinyscript.tinyactors.dev/audiences/script-author.xml), [Embedder](https://tinyscript.tinyactors.dev/audiences/embedder.xml).
Voice: [Reference](https://tinyscript.tinyactors.dev/voices/reference.xml).

> Which statements and declarations tinyscript compiles, and how far each works.

31 features: 3 implemented, 22 partial, 5 planned, 1 excluded. Back to [all areas](https://tinyscript.tinyactors.dev/reference/index.md).

| Feature | Status | What works | Test |
|---|---|---|---|
| async function | implemented | An async function declaration returns a promise the body settles: a return fulfils it, a throw or an abrupt parameter initializer rejects it. Async methods of classes and object literals are taken too. |  |
| async function* | partial | An async generator is a generator body whose next, return and throw go through the async generator driver: await suspends it as in an async function, and yield hands the driver a value to await before it settles the request. Async generator methods of classes and object literals are taken too. yield* in an async generator hands its operand to the driver, which runs the requests on its iterator until it is done. |  |
| await using | planned | Outside the first executable profile. |  |
| block | partial | Available for supported scalar expressions and statements. |  |
| break | partial | Available for supported scalar expressions and statements. |  |
| class | planned | Outside the first executable profile. |  |
| const | partial | Identifier declaration lists initialize left to right. A closure may capture a subsequent declarator and reading it prematurely raises ReferenceError. Global lexicals are visible across scripts in the same realm. Destructuring remains open. See tests/declaration-lists.js. |  |
| continue | partial | Available for supported scalar expressions and statements. |  |
| debugger | implemented | Without an attached debugger the statement completes normally. The compiler emits no instruction or host effect. | [`tests/debugger.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/debugger.js) |
| do...while | partial | Post-tested loops execute their body once before checking the condition. Break and continue target the enclosing loop. | [`tests/control.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/control.js) |
| Empty | implemented | A semicolon in statement position completes normally, including as the body of an if. | [`tests/control.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/control.js) |
| export | partial | Named function exports are callable by the embedder. Named variable exports are live bindings for linked source modules. Namespace objects and re-exports remain in scope. |  |
| Expression statement | partial | Standalone calls run in module and function bodies. Their effects are observable and their values are discarded. Expression forms such as comma and dynamic import remain open. | [`tests/module-effects/consumer.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/module-effects/consumer.js) |
| for | partial | Classic loops accept let, const and var declaration lists and comma-separated updates. Captured let bindings have distinct cells in the initializer and each iteration. See tests/declaration-lists.js. | [`tests/declaration-lists.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/declaration-lists.js) |
| for-await...of | partial | for await in an async function or an async generator takes its iterator from @@asyncIterator, or else from @@iterator with each value awaited as the async-from-sync iterator does, and awaits each next result; break, return and throw close it with an awaited return. At the top level of a module it is not built yet. |  |
| for...in | planned | Outside the first executable profile. |  |
| for...of | partial | Loop over arrays, string code points, Maps, Sets and their built-in iterators, including a dynamically typed source. Array length is read on each advance. Statically known arrays and strings use frame-local indices. A break leaves a built-in iterator positioned for its next call. User-defined iteration and closing remain in scope. | [`tests/iterators.ts`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/iterators.ts) |
| function | partial | Available for supported scalar expressions and statements. |  |
| function* | partial | An exported numeric generator can suspend, resume and unwind through its handlers using the host API. Guest generator objects remain open. |  |
| if...else | partial | Braced and single-statement branches use truth conversion. Each else binds to the nearest unmatched if. Sloppy-mode function declaration branches remain open. | [`tests/control.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/control.js) |
| import | partial | Relative named imports resolve functions and read-only aliases of exported module variables. Module-wide const, let and var evaluate initializer expressions, including calls, closures and host effects. Cyclic dependencies observe hoisted var and lexical temporal dead zones. Values persist independently per realm. Side-effect imports, including empty named lists, evaluate each reachable module once. Top-level expression statements and throw execute between declarations in source order. With a top-level await every module's steps run in one async body, so a module waiting at an await also holds back the evaluation of its siblings, which ECMA-262 evaluates meanwhile. |  |
| label | planned | Outside the first executable profile. |  |
| let | partial | An unannotated local keeps its specialized lane while its uses agree. If a later assignment or numeric update requires another representation, the compiler re-emits the function with that binding tagged. Captured mutable bindings retain their shared identity. |  |
| return | partial | Available for supported scalar expressions and statements. |  |
| switch | partial | Evaluate the discriminant once, then test selectors in source order with strict equality. Dense signed integer selectors lower to a WASM br_table. Clauses share one lexical scope and fall through. Unlabelled break and enclosing-loop continue cross finally blocks. | [`tests/switch.js`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/switch.js) |
| throw | partial | Ordinary functions throw arbitrary guest values through direct and indirect calls using a standard WebAssembly exception tag. Uncaught values reach the embedder by identity. Generator bodies support numeric throws. |  |
| try...catch | partial | Ordinary try/catch preserves object identity and supports optional, mutable and captured catch bindings. The loader prepares handler ranges once. Tag matching and stack unwinding run only when an exception is raised. Ordinary and generator functions support nested try/finally and try/catch/finally. A finalizer runs for normal completion, return, throw, break and continue. Its own abrupt completion replaces the pending one. Ordinary returns keep their native WASM representation while cleanup runs, including across host requests. Catchable built-in errors remain in progress. | [`tests/exceptions.ts`](https://github.com/tinyactors-dev/tinyactors/blob/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript/tests/exceptions.ts) |
| using | planned | Outside the first executable profile. |  |
| var | partial | Simple function-scoped names are initialized to undefined at entry. Initializers execute in source order. Repeated declarations share a binding with parameters and function declarations. Classic and for-of loops keep one shared variable across iterations. Module var initializes once per realm. Script var and function declarations install shared global properties when that script is called. A repeated var declaration preserves the prior value. Global lexical declarations use a separate realm environment. Destructuring remains in scope. |  |
| while | partial | Available for supported scalar expressions and statements. |  |
| with | excluded | Source modules are strict. Dynamic scope injection conflicts with statically resolved bindings. |  |

At tinyscript commit [`0c5984ec`](https://github.com/tinyactors-dev/tinyactors/tree/0c5984ec45040151fa4d9133cc0011950fbb90a0/tinyscript); each test is a program that runs the feature.
