Reason
  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages iconEnglish
    • 日本語
    • Deutsch
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • Українська
    • 中文
    • 繁體中文
    • Help Translate
  • GitHub

›Language Basics

Intro

  • What & Why
  • Getting started

Setup

  • Installation
  • Editor Plugins
  • Format (refmt)

Language Basics

  • Overview
  • Let Bindings
  • Primitives
  • Basic Structures
  • Types
  • Records
  • Variants
  • Options and nullability
  • Functions
  • Recursion
  • Destructuring
  • Pattern Matching
  • Mutable Bindings
  • Loops
  • Modules

Advanced Features

  • JSX
  • External
  • Exception
  • Object

JavaScript

  • Melange
  • Interop
  • Syntax Cheatsheet
  • Pipe First
  • Promise
  • Libraries
  • Converting from JS

Extra

  • Frequently Asked Questions
  • Extra Goodies
  • REPL (rtop)
Edit

Let Bindings

Quick overview: Let Bindings

A "let binding" binds values to names. In other languages they might be called a "variable declaration". The binding is immutable and can be referenced by code that comes after them.

let greeting = "hello!";
let score = 10;
let newScore = 10 + score;

Note: If you are coming from JavaScript, these bindings behave like const, not like var orlet.

Bindings are Immutable

Reason let bindings are "immutable", they cannot change after they are created.

let x = 10;
/* Error: Invalid code! */
x = x + 13;

Binding Shadowing

Bindings can be shadowed to give the appearance of updating them. This is a common pattern that should be used when it seems like a variable needs to be updated.

let x = 10;
let x = x + 10;
let x = x + 3;
/* x is 23 */

Block Scope

Bindings can be manually scoped using {}.

let message = {
  let part1 = "hello";
  let part2 = "world";
  part1 ++ " " ++ part2
};
/* `part1` and `part2` not accessible here! */

The last line of a block is implicitly returned.

Mutable Bindings

If you really need a mutable binding then check out the ref feature.

← OverviewPrimitives →
  • Bindings are Immutable
  • Binding Shadowing
  • Block Scope
  • Mutable Bindings