Functions as First-Class Values
Pass and return functions like data.
Functions Are Values
In Dart, a function is a first-class value, just like a number or string. You can store it, pass it, and return it. 🎁
Storing a Function
Assign a function to a variable by using its name without parentheses. The variable now points to the function itself.
int triple(int x) => x * 3;
var f = triple;
f(4); // 12All lessons in this course
- Declaring Functions and Return Types
- Positional vs Named Parameters
- Default Values and required
- Functions as First-Class Values