Created
January 24, 2020 08:37
-
-
Save AlexVegner/cf2b380fb204c6a5bf0f6875278f510a to your computer and use it in GitHub Desktop.
dart_lexical_scope.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Dart is a lexically scoped language, which means that the scope of variables is determined statically, simply by the layout of the code. You can “follow the curly braces outwards” to see if a variable is in scope. | |
// example | |
bool topLevel = true; | |
void main() { // | |
var insideMain = true; | |
void myFunction() { | |
var insideFunction = true; | |
void nestedFunction() { | |
var insideNestedFunction = true; | |
assert(topLevel); | |
assert(insideMain); | |
assert(insideFunction); | |
assert(insideNestedFunction); | |
} | |
nestedFunction(); | |
} | |
myFunction(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment