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
I wan't sure about the meaning of const when initialising a final variable.
In this situation const is used to instanciate (create) a new immutable object.
This means that the list object [1, 2, 3] can't be changed, and the following code won't work:
final myList =const [1, 2, 3];
myList.add(4); // error
If we ignore const then we are able to use the function add on the list, and this following code will work:
final myList = [1, 2, 3]
myList.add(4) // myList contains now the value [1, 2, 3, 4]
I recently blocked on a line similar to:
I wan't sure about the meaning of
const
when initialising afinal
variable.In this situation
const
is used to instanciate (create) a new immutable object.This means that the list object
[1, 2, 3]
can't be changed, and the following code won't work:If we ignore
const
then we are able to use the functionadd
on the list, and this following code will work:ref:
The text was updated successfully, but these errors were encountered: