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
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?
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?
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
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!
Top comments (4)
I think it would make this explanation a lot clearer if we saw real examples of data types and data structures.
By data type do you mean
int
andfloat
? What is a Javascript array? Is it a type or a structure?You are absolutely right and if you have read my post I am sure you saw that I mentioned I am going to dive deeper into data types in data structures in the next posts and this was just a basic introduction! I do not want to make my posts too long, and I want to break things down one by one and separate them into smaller posts! However, if you need information asap there are plenty of other resources where you can find the information right now if you urgently need it. If you have trouble finding it I am happy to help!
Help please share those resources
I have already made a post about data structures that you can read here: dev.to/catherineisonline/javascrip...
And about data types:
dev.to/catherineisonline/javascrip...