The function shouldn’t stop when i === 2, it simply assign an anonymous function to the variable printNumTwo^^
The problem with var is that it has a global scope, therefore even though the assignment has been done when i === 2 , when you call the function i === 3 ^^
@Advitya-sharma Just as @Layer had mentioned. The problem is that you declare your loop variable with var which has global scope (meaning it can be over-ridden without JS throwing an error). This is the cause for i === 3 on your second method call.
Interesting topic. I hope it´s OK if I ask a related follow up question.
Would another way of putting it be that when you console.log printNumTwo() at the end, it will start the anonymous function where i initially was 2. But since the loop continued after the variable printNumTwo got assigned an anonymous function, i is now 3 and the loop is finished. Therefore printNumTwo is in a way forced to display the more updated global variable i, which now is 3.