Variables and Data Types in Dart Programming Language

in CCS3 days ago

Hello everyone!

Today I am here to share variables and some data types in dart programming language. I will also share the declaration of variables.

variables in dart.png

Designed with Canva

What are Variables

The name itself suggests that a variable is something that varies. So the variables are those elements who value varies with respect to time. I will try to include some general examples to make it clear.

Examples:

  • The time is always changing so it is a variable.
  • The Earth is revolving continuously so its position is variable.
  • Weather is also a variable because it changes each moment.
  • If we see the age it is also variable which is also changing each time.
  • The prices of the goods are also variable because they changes according to the demand and supply.

Similarly in the dart programming language variables are used whose values are not constant but change with the time.

What are the Datatypes

A datatype defines the type of the variable or any other constant. It actually defines the nature and class of the variable. We know that there are different types of values some are integers, some are decimal values, some are the short/small values but some are the large values. Some are the strings. There are some list of things. Some values are available in the key value pair form. Some values only hold true or false response. So depending upon the nature and requirements specific datatypes are used.

Here are some basic datatypes which are widely used in dart programming language:

  • Int: This is used to store integer values
  • Double: This is used to store decimal/floating values
  • String: This is used to store the characters such as name
  • Bool: This is used to stored boolean values
  • List: This is used to store list of the objects in single identifier.
  • Map: It is used to store the data in the key-value pair form.

So these are the some basic and widely used built in data types in the dart programming language.

Declaration and Initialization of Variables

There are some rules to declare and initialize a variable. Each language has its own rules but most likely these are related and similar.

  • For the declaration the data type of the variable is mentioned at the start of the name of the variable. The name of the variable is also known as an identifier and each variable has a unique identifier.


image.png

  • After the declaration we can initialize the variable. For example, int age; double division:

  • We can initialize the variable on the same line where we declared it or we can declared it on a new line.

  • On the same line: int age = 12;

  • One the new line after declaring the variable: age = 22;

Now I will show you that the value of the variables changes. If after declaration we initialize it with a value of 10 and later on we store 20 then the compiler will print out the value which was stored recently.


image.png

Here you can see that age variable has 12 value in it and the compiler is printing it the same.


image.png

Now check the difference here. The compiler has printed 22 as an out value of the age variable. age variable is initialized twice where the value of the variable is changing. The compiler always show and print the recently updated value of the variable.

Now I have changed the value of the variable again and the compiler has also printed the newly updated value not the old values which were initialized later than this recently initialized value.


This is how the variables work dynamically in the dart programming language. On the whole in order to initialize the variable we have to define the datatype of the variable and then the identifier or name of the variable and then we set the value of the variable. The variable can be dynamic depending upon the requirements. Later on I will explore this dynamic nature of the variables.


All Dart Lectures

Lecture 1Write "Hello World!" Program in Dart programming Language using VS Code
Lecture 2Single Line and Multi Line Comments in Dart Programming Language - Importance of Comments in Programming

Posted using SteemX

Sort:  

🎉 Congratulations!

Your post has been upvoted by the SteemX Team! 🚀

SteemX is a modern, user-friendly and powerful platform built for the Steem community.

🔗 Visit us: www.steemx.org

✅ Support our work — Vote for our witness: bountyking5

banner.jpg

$upvote40%

 3 days ago 

🎉 Congratulations, @mohammadfaisal!

Your post Variables and Data Types in Dart Programming Language was rewarded by CCS Curation Trail

CCS Logo

“Home is where your heart is ❤️.”

👉 Join the CCS Curation Trail | Community Invitation

Vote Banner

Vote for visionaer3003 as witness