Day 0: Data Structures in JavaScript

It is technically Day 0 since I have promised to dedicate myself to maybe blog about things that I am currently learning and working on. Today, I enrolled in a class from Udemy on Data Structures in JavaScript. For far too long, JS has not been recognized as a robust Object-Oriented Programming language. I bet its reputation is still somewhat the same. Nonetheless, being able to code in JS has its advantages (of course I am slightly biased towards that).

I dislike the fact that most of the coding challenges I find online only gives me the option of writing in Python or Java (or the other real MVPs of OOP) so finding this gem on Udemy was definitely one of the most exciting things ever. The course is 3.5 hours but hopefully I can brush through faster (and more efficiently) as I move along. I think this will definitely strengthen my nonexistent CS background and hopefully move myself ahead of the list in regards to doing better in a technical interview.

function LinkedList() {
  this.head = null;
  this.tail = null;
  // won't have any nodes in it yet because there's nothing in them
}

function Node(val, next, prev) {
  this.val = val;
  this.next = next;
  this.prev = prev;
}

// Desired Outcomes = GOALS 
// adding a node to the head functionality 
// add new node to the beginning of the linked list 
// make sure the new 'head' will be pointing to the newly created node that is in the beginning of the list

LinkedList.prototype.addToHead = function(val) {
  var newNode = new Node(val, this.head, null);
  
  // assign the value of the node 
  // this.head inside the new Node refers to the new head
  // passing null as 'prev' because it will be the new head node and therefore there won't be any nodes before it
  // make sure this.head refers to the NEW head node, not the OLD head node
  
  // pretending that we already have a list of nodes, but we want to add another node to it
  
  if (this.head) this.head.prev = newNode;
  else this.tail = newNode;
  this.head = newNode;
  
};

var LL = new LinkedList();

LL.addToHead(100);
LL.addToHead(200);
LL.addToHead(300);

console.log(LL);

I have learned that comments within my code really does help myself understand what I am trying to do. Even though it might seem excessive at first, but I think that could be the best way to annotate what I am trying to achieve or what each line contributes to a greater goal. Nothing too fancy here, as I am refreshing my memory on the most common data structure patterns in the wild.