title: Reversing a Link List in JavaScript overwrites this.head and doesn't update
body: <p>Not sure what is going wrong here in the function reverseLinkedList.</p>
  <p>I'm trying to reverse a Link List and the steps I've taken seems to work at online judges like leetcode/hackerrank. Ofcourse the default structure is different when creating the Link List.</p>
  <pre><code>class Node{
    ...
  }
  
  
  class LinkedList{
    constructor(){
      this.head = null;
      this.size = 0;
    };
      
    insert(data){
      this.head = new Node(data, this.head);
      this.size++;
    };
  
    printElements(){
      let current = this.head;
      while(current){
        console.log(current.data)
        current = current.next;
      }
    };
  
    reverseLinkedList(){
      let prev = null;
      let current = this.head;
      let temp;
      while(current){
          temp = current.next;
          current.next = prev;
          prev = current;
          current = temp;
      }
    }
  }
  
  const ll = new LinkedList();
  
  ll.insert(1);
  ll.insert(12);
  ll.insert(6);
  
  ll.reverseLinkedList();
  
  ll.printElements();
  
  </code></pre>
  <p>Tried solving the same problem via leetcode/hackerrank and that works fine. I'm not sure why this is happening btw.</p>