You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can, actually. The foo variable is declared using var, making it mutable. The value initially assigned to foo is a constant (an empty list) but can be reassigned because the variable itself is not marked as const or final.
Here is an equivalent code for the above example
const arr = [];
var foo = arr;
foo = [1, 2, 3]; // CAN DO THIS!
arr = [3, 4, 5]; // ERROR - CAN NOT DO THIS!
In this case, arr is a constant and cannot be modified, but foo is a regular variable and can be reassigned to a different list without any issue.
Page URL
https://dart.dev/language/variables/
Page source
https://github.com/dart-lang/site-www/tree/main/src/content/language/variables.md
Describe the problem
var foo = const [];
foo = [1, 2, 3]; // Was const []
this was listed in the docs , but this is wrong right . we cant modify foo here
Expected fix
No response
Additional context
No response
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: