DEV Community

Vinayagam
Vinayagam

Posted on

Introduction to Variables and Data Types

Variable
1.What is a Variable?

A variable is a container used to store data values.

Think of it like a labeled box where you keep information. The label is the variable name, and the content inside is the value.
example:
let name = "Vinay";
let age = 21;

2.What is the difference between Variable and Data Type?
Answer:
A variable is the name used to store data.
A data type specifies the type of data stored in the variable.
Example:
name = "Vinay"
name → Variable
"Vinay" → String Data Type

3.Why are variables important in programming?
Answer:
Variables are important because they:

  • Store data
  • Help perform calculations
  • Allow user input handling
  • Make programs dynamic

4.Can the value of a variable change?
Answer:
Yes, the value of a variable can change during program execution.
Example:
x = 10
x = 20

Datatype
1.What is a Data Type?
A data type defines the type of value a variable can hold. It tells the program how to store and process the data.
Different programming languages have different data types, but most common ones are similar.

2.Common Data Types
Integer (int)
Stores whole numbers.
example:
age = 25

3.Float
Stores decimal numbers.
example:
price = 99.99

4.Boolean (bool)
Stores only two values:

  • True
  • False

example:
isStudent = True

5.List / Array
Stores multiple values in one variable.
example:
numbers = [1, 2, 3, 4]

Top comments (0)