How to declare variables in solidity.

How to declare variables in solidity.

Variable is a common term in programming , if you are familiar with JavaScript, C++ or any other object oriented language you should have heard the word variables. In this article i will explain in simple terms what variables are in solidity how you can declare them in solidity programming language.

CONTENT

* What is variable in solidity ?

* Types of variables in solidity ?

* How to declare variables in solidity ?

* Variable scope in solidity

# What are variables in solidity ?

In computer programming to make use of a data you have store it inside a memory, it is this memory that will hold the data and can also be referenced to anytime you want to make use of the data, this memory in computer programming is refers to as Variables.

Variables are use for storing data values which can be referenced to and be manipulated in a computer program.

# Types of variables in solidity?

In solidity variables are being classified based on the type of data they are storing, this makes it to be classified into three

(1) Boolean:- this type of variable store data that return a TRUE / FALSE value.

(2) Integers:- this type of variable are use for storing numbers.

(3) Strings:- this type of variable are use for storing letters/strings .

# How to declare variables in solidity

Unlike JavaScript where variables are being declared using keywords like var, let and const , to declare a variable in solidity the keyword to use depends on the type of data to be stored inside the variable. These keywords are :

(1) uint for declaring variables that will store Integers

(2) bool for declaring variables that will store Boolean

(3) String for declaring variables that will store Strings

Steps in variable declaration

# Variable scope in solidity In programming scope are use to determine the accessibility of variables or functions. In solidity their are two types of variable scope:

(1) State variable

(2) Local variable

(1) State variable:- These are variables that are stored inside the contract and can be accessed from anywhere inside the smart contract .

(2) Local variable:- These are variables that can only be accessed from inside the function in which they are being declared.

Click this link to see a graphical representation of variable scope in solidity

This is a simple review on what variables are and how they can be declared in solidity.

I'm eibrahim a blockchain developer and content creator.

kindly follow me on twitter, i create content on web 3 and blockchain development.

@name can be blank.eth