@IanMayo 
there is some principle in Javascript, it's called "Hoisting"