Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

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();
}

{% embed include file=“src/examples/dart-intro/lexical_scope.out)