Scope

This lesson will explain how the scope can affect the lifetime of an identifier.

We'll cover the following

Global Scope

Throughout this section, we’ve been creating and manipulating data in the outermost layer of our ReasonML program. This layer is known as the global scope.

Variables created in the global scope are accessible everywhere in the program globally.

Local Scope

As we’ll see later in the course, several operations take us into an inner layer, which is also known as a local scope. This is a contained environment. The variables and data generated in a local scope are not accessible from outside.

As soon as a local scope ends, all its data is removed from memory and cannot be recovered. In this sense, a local scope determines the lifetime of the local identifiers inside it.

A local scope is enclosed within the {} brackets. Let’s take a look at an example:

Get hands-on with 1400+ tech skills courses.