Variables inside JavaScript Functions

“It doesn’t matter where I declare my variables, right? They just get hoisted….. right?”
~ what this developer had to be thinking right before they committed this code.
Not so fast. Let’s just do a simple test using the developer tools to see whether JavaScript hoists inside functions.

function testy(){
  if(testy===true){
    console.log("It's true! I'm testy!")
  } else { 
    console.log("I'm not testy today")
  }
  var testy = true
}

Before I go showing the answer, what do you think the console shows?

.

.

.

.

.

.

.

.

Screen Shot 2018-09-18 at 9.09.42 PM

 

So it looks like JavaScript does not hoist variable declarations inside of functions. Let’s double check that with a quick change.

function testy(){
  var testy = true
  if(testy===true){
    console.log("It's true! I'm testy!")
  } else {
    console.log("I'm not testy today")
  }
}

 

What happens this time? I won’t keep you in suspense like last time:

Screen Shot 2018-09-18 at 9.12.10 PM

 

And there you have it.

Advertisements
Variables inside JavaScript Functions

But Your Github….

Screen Shot 2018-09-14 at 12.10.57 PM

This is my github contribution chart as of today (github). Of the few recruiters who have looked at my account one of them said “it doesn’t look like you contribute much code”. As I’m heavily back into the job search process I thought I would take a moment to explain “gaps”.

  1. I don’t typically contribute tutorial code. I have occasionally done so. The Harvard CS50 class requires that I have github integration so I can submit assignments. Andrew Ward’s Complete React Training at Udemy requires updates to a github repo as he has us deploy to heroku. But for the most part I figure this is code that is a) not mine and b) readily available from the original tutorial.
  2. I did commit my solutions to the homework that was assigned while I was a teaching assistant at University of Washington for a Python class. These are my original solutions to the assignments which I used as a guide for helping students. I don’t consider them tutorial or code-along-project code.
  3. The large gray chunk in June and July represents tutorial-heavy study time as well as a couple weeks I took off to prepare for my significant other’s birthday (we rented a hall, it was catered and we had out-of-town guests; things needed managing).
  4. With my previous employer my team lead was in charge of squashing commits and merging with master branch. While my unmodified code was credited to my account he most often made subtle changes (and some not so subtle) before merging. As far as git is concerned those are his commits and it was a sticking point between him, our CTO and me.
  5. Most of my code experiments end up on Repl.it or Codepen. I don’t feel the need to also commit that code to version control.

So that’s it in a nutshell.  I do code daily as I’m working to master React and the ecosystem that surround that library, as well as improving my learning in Python. While I am learning a lot and improving every day, it’s not code I’m “proud” of nor does it demonstrate my capabilities, which is what I think git should be used for outside of its professional uses.

But Your Github….