To check the layer type name use:
alert(mySelectedLayer.matchName);
A declared function will persist throughout the after effects session.
Tha tmeans that if you declared a function called createComp and then deletes that function and run the script again the function createComp will still exist in memory. This can lead to some unexpected results.