How would i pick up and drop an item with raycast

I am a pretty Intermediate scripter in unity, but I am really new to raycasts.
But anyway, I would like to know how you could pick up an item up whit raycast.

This is what I am trying to do:
You look at the item while standing closeby it (in a small area)-> you press E → the item appears in your hand → you press E again → the item gets dropped on the floor.

The most steps looks pretty easy to me, but I have no idea how I would do the first one. Please tell me how I could do that in javascript.

var hit:RaycastHit;
var pickedUpObject:GameObject;

function Start () {
 
}
 
function Update () {
 
 
if(Input.GetKeyDown("   /*  ADD YOUR KEY  */   ")){
 
    if(Physics.Raycast(transform.position,transform.forward,hit,100)){
 
    if(hit.collider.gameObject.tag=="cube"){ //add collider reference otherwise you can't access gameObject!
 
       pickedUpObject=hit.collider.gameObject; 
       hit.collider.gameObject.transform.parent=transform; 
       hit.collider.gameObject.transform.position=transform.position-transform.forward; 
       }
    }
} else { 
 
    pickedUpObject.transform.parent=null; 
    pickedUpObject=null;
 
    }
}`