title: Using linked lists in javascript
body: <p>Are there any adventage of using linked lists in javascript? Its main adventage over arrays (for example) is that we can insert element at random index without moving every element and that they are not limited to size as arrays.</p>
  
  <p>However, arrays in JS are dynamically expanded, shrink, and arrays are faster to access data. We can  also use <code>Array.prototype.splice()</code> method (indeed linked lists could be still faster than this one) to insert data.</p>
  
  <p>Are there any advantages (speed and so on) of using linked lists over arrays in JavaScript then?</p>
  
  <p>Code of basic linked lists using JS.</p>
  
  <pre><code>function list() {
  
    this.head = null;
    this.tail = null;
  
    this.createNode=function(data) {
      return {data: data, next: null }
    };
  
    this.addNode=function(data) {
      if (this.head == null) {
        this.tail = this.createNode(data);
        this.head = this.tail;
      } else {
        this.tail.next = this.createNode(data);
        this.tail = this.tail.next;
      }
    };
  
    this.printNode=function() {
      var x = this.head;
      while (x != null) {
        console.log(x.data);
        x = x.next;
      }
    }
  }
  
  var list = new list();
  list.addNode("one");
  list.addNode("two");
  list.printNode();
  </code></pre>