DEV Community

Discussion on: var vs dynamic in Dart

Collapse
 
dance2die profile image
Sung M. Kim

Thanks for the post, Nitish 👍

I've never used Dart and the post was very easy to follow.
How I understood about var in Dart is that, Dart keeps track of initial variable type while dynamic.

And shouldn't the example 4 use dynamic keyword?

// This is invalid Example this will work
void main() {
     dynamic x = 'Math pi';
     print(x); // Maths pi
     x = 3.14; 
     print(x); // 3.14
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
slaveofcode profile image
Aditya Kresna

Awesome!