Does MV initialize all variables?

I was using a variable in a damage formula and it created some odd results in the troop playtest. Basically, it caused the whole equation to come back 0, which to me suggested the variable generated some kind of error or special value. But it worked fine when I ran the playtest. I'm kind of puzzled: was this more weird caching behavior? Does MV actually initiatize all variables you will call when it compiles? Or is this behavior unpredictable and should I just set all my variables to initial values myself like a good little programmer?
No, the game variables are just members of an array, and there isn't any process that tries to parse your map/event files to see which IDs you use during the game every time it boots up.

So until you assign them a value, they'll return undefined if you use them in an equation, just like any other uninitialized variable in JavaScript - it's up to you to make sure it's assigned a value before you use it.
like @ATT_Turan said above... you might want to make sure you set your variable in the correct time...
for easier debugging time... you can try having one troop event at turn 0 that show message that print your variable using \v[yourvariableidhere]... you can know what the variable value at the start of the battle before entering the damage formula equation... hope this help...
Just to expand upon what other people have said, the engine doesn't initialize your variables, but it does convert undefined variables to 0 when you access them via normal means:

JavaScript:
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] || 0;
};

However, this protection is bypassed when using v[] in damage formulas, because then you're accessing the array directly, instead of through the value function.
For this reason, it can be good to reference variables like this in a damage formula:

(v[1] || 0)
I.e. "get the value of game variable 1, or 0 if it is falsy":
Just to expand upon what other people have said, the engine doesn't initialize your variables, but it does convert undefined variables to 0 when you access them via normal means:

JavaScript:
Game_Variables.prototype.value = function(variableId) {
    return this._data[variableId] || 0;
};

However, this protection is bypassed when using v[] in damage formulas, because then you're accessing the array directly, instead of through the value function.

Ah!

Original thread: https://forums.rpgmakerweb.com/threads/does-mv-initialize-all-variables.144649/