How to know how scripting behaviors work

Hi I'm wondering how to know how values, vars, prefabs, etc. work and how to type pacific scripts to get things working without problems etc. like for an eg. (this is someone else's idea not mine but any way) if you want an object to act like a player that can walk etc. this is the code.

var speed = 3.0;
    var rotateSpeed = 3.0;
    function Update ()
        {
            var controller : CharacterController = GetComponent(CharacterController);
            transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
            var forward = transform.TransformDirection(Vector3.forward);
            var curSpeed = speed * Input.GetAxis ("Vertical");
            controller.SimpleMove(forward * curSpeed);
        }
    @script RequireComponent(CharacterController)

How am I suppose to know how all of that stuff works?

In the script editor you can highlight a piece of code and in the toolbar click the arrow icon with a question mark next to it, this will open your default browser and direct you to the relevant script reference page which will explain it.