Thanks JavaFan and LanX.
Points on compile-time and run-time difference are well taken.
BTW, in my original code, I do use strict/warning,
and knew that separating the declaration and condition statement makes it work as expected. But still knowing a little more about what is going on under the hood is more satisfactory.