title: Have confusion about the accessing null's next property?
body: <p>I am learning DS with javascript.
  While implementing linked list push() method in ll my mentor wrote code.
  But I am unable to understand a part of that.</p>
  <p>Here in SinglyLinkedList class I have initialize this.tail = null but in push method's else block trying to access the property next  | this.tail.next = newNode | which doesn't exist ....but still program is working properly.</p>
  <p>Pls explain me this... Why</p>
  <pre><code>class node {
  
  
  constructor(val) {
      this.val = val;
      this.next = null;
    }
  }
  class SinglyLinkedList {
    constructor() {
      this.head = null;
      this.tail = null;
      this.length = 0;
    }
    push(val) {
      var newNode = new node(val);
      if (!this.head) {
        this.head = newNode;
        this.tail = this.head;
      } else {
        this.tail.next = newNode;
        this.tail = newNode;
      }
      this.length++;
    }
  }
  </code></pre>