While in Norse mythology, trolls were magical and sometimes beautiful creatures, with special skills, in Tolkien's writings they are portrayed as cruel and stupid, with crude habits, although still intelligent enough to communicate with a known language.
In The Hobbit, Bilbo Baggins and the Dwarf company encountered three trolls on their journey to Erebor. The trolls captured the Dwarves and prepared to eat them, but Gandalf managed to distract them until dawn, when exposure to sunlight turned them into stone. They spoke with thick Cockney accents, and even had English names: Tom, Bert, and William.
In The Lord of the Rings, Treebeard remarked that trolls were "made ... in mockery of Ents", as Orcs were of Elves. Trolls' origins are fully detailed in The Silmarillion. Morgoth, the evil Vala, created the first trolls before the First Age of Middle-earth. They were strong and vicious but stupid creatures. Their major weakness was that they turned to stone in sunlight.
During the wars of Beleriand, Gothmog (the Lord of Balrogs) had a bodyguard of trolls. During the Nírnaeth Arnoediad, the Battle of Unnumbered Tears, in which Morgoth defeated the united armies of Elves, Men, and Dwarves, the great human warrior Húrin faced Gothmog's trolls to protect the retreat of the Elven king Turgon. As Morgoth had ordered to capture Húrin alive, the warrior managed to wipe out the trolls before being captured by orcs.
Many trolls died in the War of Wrath, but some survived and joined Sauron, the greatest surviving servant of Morgoth. In the Second Age and Third Age, trolls were among Sauron's most dangerous warriors.