Doubly Linked List in JavaScript Last Updated : 29 Aug, 2025 Comments Improve Suggest changes Like Article Like Report A doubly linked list (DLL) is a special type of linked list in which each node contains a pointer to the previous node as well as the next node of the linked list.To create a doubly linked lists, we have to create the following classes:Node Class: To implement and create elements and link other elements.Doubly Linked List Class: To store and access all nodes of the list.Doubly LinkedList Node is constructed of the following items:A class named nodeA class constructor, andData items/variablesdata: to contain respective node valuenext: to link the next node with the default value as null.prev: to link the previous node with the default value as null.Example: JavaScript // Doubly Linked list Node class Node { // Constructor to create a new node // next and prev is by default initialized as null constructor(val) { // To store the value this.data = val; // To link the next Node this.next = null; // TO link the previous Node this.prev = null; } } Doubly Linked List is constructed of the following items:Class Named DoublyLinkedListA constructor to create the DLLData items/variables:head: to store the starting nodetail: to store the ending nodeExample: JavaScript // Doubly Linked List class DoublyLinkedList { // Constructor to create a new linked list constructor() { // To contain the first item of the list this.head = null; // To contain the last item of the list this.tail = null; } } Basic Operations in Doubly Linked Lists:Method to Check if the List is Empty:Check if the head is null or not and return result JavaScript // To check if the list is empty isEmpty() { if (this.head == null) return true; return false; } Method to Insert Element:Create a new node with value as argumentCheck if the head is null insert at headElse insert the new node at the tail and shift tail pointer JavaScript // Method to add item at the last of doubly linked list addItem(val) { // Create a temporary variable let temp = new Node(val); // If the list is empty link assign // new node to both head and tail if (this.head == null) { this.head = temp; this.tail = temp; } // else add item to the tail and shift tail else { temp.prev = this.tail; this.tail.next = temp; this.tail = this.tail.next; } } To traverse and display the list:Check is the list is not nullUse a current poiter to treaverse the list and display value using console.log() JavaScript // To traverse and display the list display() { // Check if the List is empty if (!this.isEmpty()) { // traverse the list using new current pointer let curr = this.head; while (curr !== null) { // Display element console.log(curr.data); // Shift the current pointer curr = curr.next; } } } Implementation of Doubly Linked ListExample: This example demonstrate the basic implementation of a doubly linked list. JavaScript // Doubly Linked list Node class Node { // Constructor to create a new node // next and prev is by default initialized as null constructor(val) { // To store the value this.data = val; // To link the next Node this.next = null; // To link the previous Node this.prev = null; } } // Doubly Linked List class DoublyLinkedList { // Constructor to create a new linked list constructor() { // To contain the first item of the list this.head = null; // To contain the last item of the list this.tail = null; } // To check if the list is empty isEmpty() { if (this.head == null) return true; return false; } // Method to add item at the last of doubly linked list addItem(val) { // Create a temporary variable let temp = new Node(val); // If the list is empty link assign // new node to both head and tail if (this.head == null) { this.head = temp; this.tail = temp; } // else add item to the tail and shift tail else { this.tail.next = temp; this.tail = this.tail.next; } } // To traverse and display the list display() { // Check if the List is empty if (!this.isEmpty()) { // traverse the list using new current pointer let curr = this.head; while (curr !== null) { // Display element console.log(curr.data); // Shift the current pointer curr = curr.next; } } } } // Create new Doubly Linked List const dll = new DoublyLinkedList(); // Add elements in the list dll.addItem(25); dll.addItem(27); dll.addItem(17); dll.addItem(29); // Display the list dll.display(); Output25 27 17 29 Doubly Linked list Visit Course Comment More info J jatinsharmatu54 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-DSA Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like