Part 2 — (Introduction to Linkedlist in JavaScript) How Linked List works in JavaScript

Vasanth Bhat
JavaScript in Plain English
2 min readMay 2, 2021

--

If you directly landed on to this article, then before reading further, read my previous article on how to implement Linked List in JavaScript here.

Assuming you have read my previous article above, you also know that everything is object in JavaScript. Hence, even the Linked List has to be an object. Unlike strongly typed languages like Java, C, C++ which will interact with system memory directly, JavaScript doesn’t interact with system memory; instead, it is fed as a language to an underlying compiler and they will execute the JavaScript code on our behalf and return the result.

Data Structures like Arrays, Linked Lists, Trees, etc interact with memory locations and below is the typical arrangement of Linked List in a strongly typed language, where the location starting from 3200 is allocated to Linked List.

Source: https://beginnersbook.com/

The same doesn’t happen in the case of JavaScript. Below is the Linked List representation in the case of JavaScript.

head : { next: {    element: 10,    next: {     element: 20,     next: ….    } }}

So, behind the scenes, Linked List in JavaScript is nothing but a set of objects which are looped one inside another. So, from the above example, head.next will give the first node which contains a key called element which contains an element, and another term next which will point to the next node.

If you understand this concept very well, then you can do all the complex operations of the Linked List in JavaScript. If you have any doubts mention them in the comment box. I will answer at the earliest.

In the next article, let’s learn how to answer some common questions asked in interviews like reversing a Linked List, finding the middle element, etc. Stay tuned.

Don’t forget to read the next article

Part 3 — How to find middle element in the linked list using JavaScript

Other articles from the same author:

  1. How everything is Object in JavaScript?
  2. Hoisting in JavaScript : Hot topic for Interview
  3. Memoization in JavaScript — Hot topic for Interview

Click here for all the articles by the author.

More content at plainenglish.io

--

--

Mobile Application Developer at Walmart. 6+ years of Software experience, Scalability Specialist, Coffee lover, likes travelling and writing.