In this article, we are going to cover the concept of linked lists, what linked lists are and how to implement one in your project. This article covers the basic way to implement a linked list in JavaScript.

In this article, i will assume that you already know or have a basic knowledge of javascript and general programming concepts like strings and arrays.

A linked list is just another data structure like arrays , stacks or queues. A linked list unlike an array contains nodes where each node has a data part which stores our data and a next part or a reference to the next node in the list.

The nodes are connected together through links. In a more simple term, a linked list is a collection of nodes which are connected to each other through links. These nodes have two parts. The first part stores our data while the second part stores the address or link to the next node in the list.

Consider the diagram below.

The first node in a list is usually called a head. The head links to the next node through the next link and it continues till the last node which is not pointing to any other node, so the next value of the last node becomes NULL.

Linked lists cannot be accessed randomly. I.e you cannot access data with it’s index (this can be manipulated but it’s not like we do with arrays). In linked lists, we refer to the memory location Address, not the index location.

Now that we have a better understanding of linked lists. Let’s go on and implement it using javascript.

The first thing we are going to do is to create a node constructor function or class. I will be using ES6 classes in the article.

class Node{

constructor(data, next = null){
this.data = data;
this.next = next;
}

#javascript-tips #programming #linked-lists #javascript #javascript-development

How To Implement Your First Linked List Data Structure In JavaScript
1.50 GEEK