Yep! It needs to be declared locally.
Well, not really.
It doesn't have to be declared locally. But the value needs to be assigned from within the resize callback! Where it is declared is irrelevant.
It's just that you'd assigned the value only once, when the page was loaded.
If you declare where you did originally, you'd create a closure variable. In this case, there's no sense in doing that, and, yes, I would agree you should move the declaration inside of the callback. But it would still work with the declaration (not the assignment) in the original location. Closure variables can be quite handy, though, in other scenarios, as any functions declared within the scope of closure variables can access them.