Tetrahydrocannabinol (THC, dronabinol by INN), or more precisely its main isomer (−)-trans-Δ9-tetrahydrocannabinol, is the principal psychoactive constituent (or cannabinoid) of cannabis. It can be an amber or gold colored glassy solid when cold, which becomes viscous and sticky if warmed.
Like most pharmacologically-active secondary metabolites of plants, THC in Cannabis is assumed to be involved in self-defense, perhaps against herbivores. THC also possesses high UV-B (280–315 nm) absorption properties, which, it has been speculated, could protect the plant from harmful UV radiation exposure.
Source: Wikipedia: Tetrahydrocannabinol