Lexical Scoping


Curly braces define scope. Both for regular variables and for functions. We cannot use the global version of f() if we declare f internally as well.


examples/dart-intro/lexical_scope.dart
h() {
  print("In external h");
}


f() {
  print("In f");
  g() {
    print("In g");
  }
  h() {
    print("In internal h");
  }

  g();
  h();
}


main() {
  f();
  //g();   // Not declared


  //f() {
  //  print("New f");
  //}

  h();
}

In f
In g
In internal h
In external h