title: I am trying to understand the concept of passing my reference (pointers) in a Singly Linked List implementation in JavaScript
body: <p>I am trying to implement a singly linked list in JavaScript and I am having a hard time visualizing the concept of passing my reference (and what is pointing where). My code is below and I have followed it up with a few questions or my understanding, can you please go over it and let me know if I am thinking in the right direction.</p>
  
  <pre><code>class Node{
      constructor(val){
          this.val = val;
          this.next = null;
      }
  }
  
  class LinkedLists {
      constructor(){
          this.head = null;
          this.length = 0;
          this.tail = null;
      }
  
      // methods
      addNodeStart(val){
          let node = new Node(val);
          if (this.length === 0){
              this.length++;
              this.head = node;
              this.tail = node;
  
          } else {
              node.next = this.head;
              this.head = node;
              this.length++;
          }
          return this;
      }
  
      addNodeEnd(val){
          let node = new Node(val);
  
          if (this.length === 0){
              this.length++;
              this.head = node;
              this.tail = node;
  
          } else {
              this.length++;
              this.tail.next = node;
              this.tail = node;
          }
      }
  }
  </code></pre>
  
  <p>My Understandings:</p>
  
  <ol>
  <li>In adding a node to the start (addNodeStart) first we create a new Node with the given val and put the if statement to check if the length is 0 and then set the tail and head both to the new node.</li>
  <li>Else If the length > 1, then first point the <code>node.next</code> to <code>this.head</code> (this.head is pointing to a Node which was set as the head). So is <code>this.head</code> just a container holding the reference to a node?? or is this.head an actual node? Then again set this.head to node. So is this.head just a variable name, for example let x = 5; here x references to the memory location of 5.</li>
  </ol>
  
  <p>So is my thinking of this.head being just a container (variable) that holds the value of a node? or am I missing the something here?</p>