For more on this, see:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var

"For that reason, it is recommended to always declare variable at the top of functions. Otherwise, it may lead to confusing cases:"