Search⌘ K

Function Scope

Explore how function scope works in ReasonML, including the lifecycle of variables inside functions, let bindings, and interaction with global variables. Understand how immutability affects higher-scope values and how ReasonML manages multiple function definitions, preparing you for advanced concepts like recursion and currying.

Inside the Function Body

In Reason, data created inside the body of a function will not exist outside it. Only the value we return is accessible. For example, this code will produce an error:

Reason
let a = 10;
let b = 5;
let product = (a, b) => {
let c = 20;
a * b * c;
};
/* Accesing c outside the function */
c;

Redefining a Function

Because of let bindings, we can use the same identifier to define different functions. The latest definition will be ...