Main page

How to create linked list in javascript with ES6 classes

javascript data-structure interview es6 linked-list english


In this post, I'd like to share my implementation of LinkedList in JavaScript using mechanism of ES6 Classes.


class LinkedList {
    constructor() {
    this.head = new Node("", null);
  addNode(node) {
    let curr = this.head;
    while( {
      curr =;
    } = node;


class Node {
    constructor(data, node) { = data; = node;

How to use it

let linkedList = new LinkedList();

// add some nodes
linkedList.addNode(new Node("1", null));
linkedList.addNode(new Node("2", null));
linkedList.addNode(new Node("3", null));

// console.log nodes, just to verify that everything works fine ;)
let current = linkedList.head;
while( {
    current =;


<iframe width="100%" height="300" src="//,result/dark/" allowfullscreen="allowfullscreen" allowpaymentrequest frameborder="0">

Happy creating your own linked lists! :)