Day 56: var a = a is Okay in JavaScript?

I was reading through some example code in an older blog post. The JavaScript file started off by declaring a namespace and it used an interesting syntax to check if the namespace already exists. But I thought it would cause an error. Apparently in JavaScript you can declare the same variable with var or let multiple times within the same scope without causing any errors. This was shocking to me but I learned that it had to do with how JavaScript is processed. There is a memory allocation phase where declarations take place and then there is the execution phase where initializations take place… I think. Long story short we can declare the same variable any number of times anywhere in our script and it will not throw an error. This is due to the processing method of JavaScript and the fact declarations are hoisted just like function declarations. Overall it was an interesting topic to learn about.

TLDR;

Okay, so here are the highlights of what I did:

  • JavaScript -> Read through the MDN Docs on var variable declarations I also found a great Stack Overflow Question that helped me understand why a statement like var a = a in JavaScript does not cause an error. I originally thought declaring a variable that already exists throws an error. but apparently there is more to the story. I think in strict mode it still does.
  • Practice -> Continued working on the AirBnB Experiences project from the React tutorial course. The video spends so much time on the CSS. I’m interesting to see how other people do things but it is getting to be a large chunk of the video. So far nothing too interesting. Working off the Figma designs is getting easier though. I’m getting more comfortable with the tool. It has it’s perks.


Goal For Round 7 of the #100DaysofCode Challenge

This is my seventh round of the “#100daysofcode” challenge. I will be continuing my work from round five and round six into round seven. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in turn derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.

I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.