In a function, how do I access a variable of another function in the SAME script? (js)

I have a script, with 2 functions. These 2 functions are called at different moments, by another script on another gameObject.

The first function, creates a variable (it's the length of an array that this 1st function creates at runtime using "GameObject.FindGameObjectsWithTag").

I want to use this variable that the 1st function creates in the 2nd function, but when I put it in the 2nd function like this:

while (varName >=1) { ...

I get the error:

"varName" is not a member of 'function ():void'

What should I do then, to use in the 2nd function, the variable that the 1st function creates?

You need to declare the variable outside of the functions. That way, it's in the scope of the class, which lets you use it from both functions

i.e.

var test : int;

function a()
{
    test = 4;
}

function b()
{
    Debug.Log(test);
}