Skip to content

Commit

Permalink
Add section on shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
suaviloquence committed Aug 7, 2024
1 parent 407228a commit 1775b60
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/src/language-concepts/statements-and-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,31 @@ more in depth in the section on element contexts).
The next (and maybe most important) type of value is the [`Element`](./elements-and-selectors.md)
which will let us read data from a web page, explained in the next section.

## Shadowing

It is possible to have two statements bind values to the *same name* in the same scope.
This is called **shadowing**. Only the last (bottommost) statement with a given
name will appear in the program output, but at any point, referencing `$name` will
give the current most recently defined binding of that name.

### Example

```scrp
output: "Not me!";
output: "or me...";
// save $output at this point in time
snapshot: $output;
output: "I will be the final result!";
```

will output:

```json
{
"output": "I will be the final result!",
"snapshot": "or me..."
}
```

[^element-caveat]: Elements are only available inside an *element context*
and are not outputted in the final result.

0 comments on commit 1775b60

Please sign in to comment.