What is the Difference Between Data Type and Data Structure?

Ekaterine Mitagvaria - Jan 27 '23 - - Dev Community

In JavaScript, there are many terms and explanations that sound so similar to each other that for a beginner it can become a little confusing. And it is definitely confusing because the definitions are sometimes exactly the same but the last word in the description is a little different!

Today, I will try to break down the difference between data types and data structures so we can move on to data types and data structures in JavaScript in more detail which is a crucial topic in JavaScript.

Definition

Definition

The data type is a categorization of specific types of values on which we can perform the same operations. It’s like having a specific label to tell the computer what data we are giving to it. This helps the computer to understand what to do or what can be done with the data so it can respond with a correct result. If let’s say I told the computer to calculate the sum of a letter and a number it wouldn’t understand what to do if it didn’t know that one is a number and the second is a letter.

Data structure however is a collection of various data types. It makes it easier to organize, find or manipulate data when they are organized in a specific order or place.
So it’s a group of data types labeled and organized in a specific way.

What does it store?

What does it store?

Data type stores a specific type of data that can vary. It can be letters or numbers and some other values. For example, we can have different data types in clothing like dresses, t-shirts, skirts, and so on.
Data type also can store particular values. So if I have a data type for clothing, I will not be able to store vegetables there.

Data structure however store the data types but specific collections of these data types. Just like in clothing, we can create a data structure for summer clothing that holds different types of clothing types but are specific only for summer.
The data structure can store any type of data in the same structure and doesn’t have to be the same as in data types.

How do we save values?

How do we save values?

In data types we usually save values directly and don’t have to create data types, they already are predefined. In some languages however, you have to indicate what exact predefined data type it is going to hold in the future while in another language the data type is indicated the moment we assign it a value. In JavaScript when I assign a number value, the data type is defined at that moment and I do not have to write in advance that it will hold a number value.

In the data structure, you cannot just assign value, because it is a type of box that has other boxes inside it sometimes, not just a label. So there are different types of operations we perform to push the information to the data structure. Something similar to adding things to the box, e.g. remove, add, and so on.

Difference across languages

Difference across languages

Both data types and data structures can vary depending on the programming language. Some languages have similar data types of data structures and some have ones that others don’t. However, we are going to discuss JavaScript data types and structures in the next posts!

📌 Enjoyed the post? Please let me know in the comment down below!

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player