Lexical scope

Dart is a lexically scoped language, which means that the scope ofvariables is determined statically, simply by the layout of the code.You can “follow the curly braces outwards” to see if a variable is inscope.

Here is an example of nested functions with variables at each scopelevel:

1. bool topLevel = true;

3. void main() {
4. var insideMain = true;

6. void myFunction() {
7. var insideFunction = true;

9. void nestedFunction() {
10. var insideNestedFunction = true;

12. assert(topLevel);
13. assert(insideMain);
14. assert(insideFunction);
15. assert(insideNestedFunction);
16. }
17. }
18. }

Notice how nestedFunction() can use variables from every level, allthe way up to the top level.