Who is effective?

I have a question, there are two codes in below:

A code:

var script : JavaScript;
function Update ()
{
    script.ProcessSomething();
}

B code:

function Update ()
{
    script = GetComponent(JavaScript);
    script.ProcessSomething();
}

is the A more effective than the B?

Yes, A is more effective than B since B will request a component each frame where A will not.

Note that there is a mix of both, let’s call it solution C, which get the best of the two approaches:

var script : JavaScript;

function Start ()
{
    if (!script)
        script = GetComponent(JavaScript);
}

function Update ()
{
    script.ProcessSomething();
}

This allow you to optionally set a script reference in the inspector, or if it is null, it will during start attempt to find the script on the same object.

The first one will use “more” (not really) memory, but be quicker, the second one will use “more” (also not really :D) time to process. In the end the difference will be close to nothing my guess would be.