Lexical closures

 /// What is Closure ?

/// Ans: A Closure is function object that has access to variables in its lexical scope,
/// even when the function is used outside of its original scope

/// Example of Lexical Closure
// void main() {
// var a = 0;
// print("Main function = $a");
//
// void outer() { // This is Lexical scope
// a = 5;
// print("Outer function = $a");
// }
//
// outer();
// }

/// Another Example of Lexical Closure
var a = 0;

void main() {
print("Main Function : $a");

void outer() {
a = 5;
print("Outer Function : $a");
}
outer();
demo();
}
void demo() {
a = 20;
print("Demo Function : $a");
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter