Data Structures In JavaScript

If you’re into programming, most likely you’ve heard of Data Structures. But, as a web developer, we often overlook it. We can build a web without learning it too deeply. So, what exactly is a Data Structure?

Data structure is a specific format we use to store, manage and organize our data so that it can be used efficiently.

If you’ve learned JavaScript, you’d be familiar with arrays and objects. Well, those are examples of data structures. You can store data in it whether it is integer, strings or other forms.

But, data structures in each programming language may vary. For example, in languages like C, you have to specify the length of the array. While in JavaScript, you just have to define it once and use it without worrying about the length.

So, I’ll introduce you to the basic overview of data structures and why is it important.

Types Of Data Structures In JavaScript

  • Arrays are collections of items with index-value pairs with indexes starting from 0.
  • Objects are collections of items with key-value pairs.
  • Stacks are lists that behave like books. Imagine you have books stacked over. To add an item, you put it at the top and to remove an item, you take it from the top. That principle is called LIFO (Last In First Out)
  • Queues are lists that behave like people queueing at a store. The ones that come first are first served and it is called FIFO (First In First Out). It is the opposite of Stacks.
  • Linked Lists are lists in which their items point to each other. So, to access a certain item, you have to go through the first item until you get to that item. All the items are connected.
  • Trees are lists that in which their items or nodes have parent/child relationship. One item (parent) can point to multiple items (children) and keep going on until they form a tree structure.
  • Graphs are structures that can connect with each other in an unstructured way.

Why Is It Important?

Choosing the right data structure can give a great performance boost to an algorithm. But, using the right data structure from the start is better obviously.

Using certain data structures can be faster depending on the case. You wouldn’t want to cook with a screwdriver right? Choosing the right tool for the right job is an important part in programming.

Putting the right data structure into a slow program can work the same wonders as transplanting fresh parts into a sick patient.


Closing Statement

This is a very brief overview of data structures in JavaScript. For a more formal material on DSA, I recommend reading The Algorithm Design Manual by Skiena. Although it is not in JavaScript, I’m sure you can understand it just fine. Check out my upcoming posts for more in depth explanations on each data structures in my blog.

Also check out an inseparable topic from Data Structures in my other post, What is Algorithm And Why is It Important?

Leave a Comment