First off, please understand that mothballs are a PESTICIDE and can be harmful if not used according to label instructions. Mothballs contain napthalene (I made napthalene in a college chemistry class as one of our laboratory experiments) or paradichlorobenzene as the active ingredient. Both products are fumigants, or volatile chemicals that vaporize at lower temperatures (i.e. room temperature). While "mothballs" is a common term that most are familiar with, these fumigants may also come in the form of cakes, crystals, tablets, bars, among others.
To use the products properly, they should be used in an AIRTIGHT space, such as a well-sealed container, garment bag, etc. They should not be placed in an open container, in a closet or attic, or sprinkled willy-nilly throughout the home (hello great-grandma!). As with all pesticides, you should read and follow all label instructions. All pesticides, including mothballs, should be kept out of reach of children and pets (mothballs can be mistaken for candy, so this is really important).