ReScript for JavaScript Developers

If you already write JavaScript, ReScript should feel familiar quickly. This page is a compact syntax guide for the main differences you should be aware of.

For a guided migration workflow, see Converting from JS.

What to know first

Quick reference

TopicReScriptNotes for JavaScript developers
Semicolonslet x = 1Semicolons are not required. See Overview.
Comments//, /* */, /** */Familiar syntax, including doc comments. See Overview.
Variableslet x = 5let creates an immutable binding. See Let Binding.
Mutationlet x = ref(5)Mutable state is explicit through ref or mutable fields. See Mutation.
Strings"hello"Strings use double quotes. See Primitive Types.
String concatenation"hello " ++ nameReScript uses ++ for strings. See Primitive Types.
Interpolation`hello ${name}`Template strings work similarly. See Primitive Types.
Equality===, !==, ==, !=No coercive equality. == and != are structural. See Equality and Comparison.
Numbers3, 3.14, 2.0 * 3.0Arithmetic operators work for both int and float. See Primitive Types.
Records{x: 30, y: 20}Similar object syntax, but records are typed. See Record.
Arrays[1, 2, 3]Arrays are homogeneous. See Array and List.
Mixed fixed-size data(1, "Bob", true)Use tuples instead of heterogeneous arrays. See Tuple.
Missing valuesoption<'a>Use Some(value) and None instead of null and undefined. See Null, Undefined and Option.
Functionslet add = (a, b) => a + bFamiliar arrow-style syntax. See Function.
Blocks{ let x = 1; x + 1 }The last expression is returned implicitly. See Overview.
Conditionalsif cond {a} else {b}if is an expression. See If-Else & Loops.
Pattern matchingswitch value { ... }Use switch for destructuring and exhaustive branching. See Pattern Matching / Destructuring.
Destructuringlet {a, b} = dataWorks for records, arrays, tuples, and more. See Pattern Matching / Destructuring.
Loopsfor i in 0 to 10 {}for and while exist, but collection transforms are also common. See If-Else & Loops.
Exceptionsthrow(MyException(...))throw and try exist, but typed data flow is preferred where possible. See Exception.
JSX<Comp message />JSX is supported directly, with a few ReScript conventions. See JSX.

Where to Go Next