This code works in javascript. but it is better to move the var up to the top of the method, since it is going to be used outside of this if statement.  If we ported the code to use ES6 let, it would break.