Variables in Dart
Tags: dart, flutter, beginners, todayilearned
Published: 2019-09-15 20:25:45

Variable declaration and its fundamentals are the basic building block of any programming language. Let’s explore a little bit about dart variables.

> **Variable is a named space in memory that stores value. You can say that it is a container for data.**

####Following are the naming rule for a variable.

* Identifiers cannot be keywords.
* Identifiers can contain alphabet and numbers. But identifier cannot start with a number.
* Identifiers cannot contain white spaces and special characters except underscore (_) and the dollar ($) sign.

##Variable declaration Syntax

* In dart a variable must be declared before it is used.
* Example of creating and initializing the variable.

```dart
var name = “Akshay”;
```

* Here ***var*** is a keyword used to declare a variable.
* Dart supports a type-inference. So that here compiler will automatically know that this is a variable of type string by the initializer.
* Here you can explicitly specify the type of a variable by prefixing it. Consider below example:

```dart
String name = "Akshay";
int highScore = 120;
```

All the variables in dart store a reference to the value rather than containing a value. Here variable **name** contains a reference to a string object with a value of “Viveki”.

###The Dynamic Type

* Variables declared without a static type are implicitly dynamic.
* If a variable is not restricted to a single-type, specify it as dynamic type.

```dart
dynamic score = 56;
```

##Default Values

All uninitialized variables have an initial value of ***null***.

Even variables with numeric types are initially null because numbers — like everything else in dart — are objects.

```dart
void main() {
  int highScore;
  print(highScore);
}

Output
null
```

That’s all you need to know about the basics of variables in the dart. Feel free to let me know if I miss something. I’ll love to learn it.

Till then Keep Loving, Keep Coding. I’ll catch you up in the next article.

Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitate that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.

###For More Information Please Visit Following Links
* [Fuchsia OS official site](https://fuchsia.dev/)
* [Dart official site](https://dart.dev/)
* [Flutter official site](https://flutter.dev/)

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

- [My Site] (https://www.jaytillu.in)
- [My Blogs] (https://blogs.jaytillu.in)
- [Twitter](https://twitter.com/jay_tillu)
- [Facebook](https://www.facebook.com/jaytillu.1314/)
- [Instagram](https://www.facebook.com/jaytillu.1314/)
- [Medium](https://medium.com/jay-tillu)
- [LinkedIn](https://www.linkedin.com/in/jaytillu/)
- [Github](https://www.github.com/jay-tillu)
- [Stack overflow](https://stackoverflow.com/users/8509590/jay-tillu)
or just mail me at jd.tillu@gmail.com