Dart (7 Part Series)
In this post we're going to learn about variables in Dart, variables are like tiny-boxes that keeps references to a value, and this tiny-box can have a name so we can identify and remember it pretty easily.
In Dart, we can create variables in three ways:
We can create a variable using the reserved keyword var before the name of the variable and the value. Here's an example:
var year = 1990; print(year) //The result is going to be: 1990
This is called Type inference. What it does is that the compiler can automatically deduce the type of the variable or an expression.
We can also declare the type of the variable as follows:
String name = "John";
//The result is going to be: John
The dynamic keyword allows us to declare a variable that the type can change at execution type and can be defined in this way:
dynamic changeType = 1234
The type can change at runtime
changeType = "I'm a string now"
//The result is going to be: I'm a string now
You can try these concepts in IDE like Intellij idea community which is free, all you need is to install the Dart Plugin. Or in some online editors like Dartpad.
If you liked this post I'm actually writing more like these in a free ebook which is a basic course of Dart that can help you to start with Flutter, that awesome framework for develop multiplatform apps. If you're interested you can get it for free following this link..