I saw these pieces of code in a book. Following are my observations :
1> The var variable lives in global scope so the onclick handlers uses value of i that is present in alert is not static but dynamic in nature.
2> If the let keyword is used . It does not give me the latest value of "i"(i.e 5) but gives me 0,1,2,3,4. The for loop does not executes again even after multiple clicks(tried conosle.log). That means value of "i" in alert either is static as the code is not executed again