Variable values are stored. Here's some clarification from a developer:
Your properties and variables will always save their values for as long as the instance of the script exists and isn’t reset. For a repeatable quest, you’ll keep everything until the quest is started up. If it’s on a reference, you’ll keep everything until your cell resets (if the reference is flagged to reset). If it’s on an active magic effect, you’ll keep everything while the effect is applied to its target (after that the script instance is deleted as soon as you stop doing things with it). For more information on resetting, you should take a look at http://www.creationkit.com/OnReset_-_ObjectReference#Notes.
Any variables you define inside a function will be discarded as soon as you leave the function, similarly to most other scripting and programming languages.
Cipscis