Significance
Mothballs have a strong odor that rats do not like. Placing mothballs in areas that are believed to be infested with rats can drive them out of their location, forcing them to find a new place to breed.
Function
The chemicals in mothballs are fumigants that must be present in high concentrations to be effective as a rat deterrent, but that can be dangerous for anyone exposed to them.
Other Deterrents
Toilet bowl cleaner, cat litter and pellets with the scent of rat predators are also used to deter rats.
Considerations
A safer way of preventing rats from entering your home may be with the use of an ultrasonic rat repellent machine. This ultrasonic sound is not able to be heard by anything other than rats and is designed so that the sound is always bothersome.
Warning
Mothballs are made from two very toxic chemicals, and it is no longer recommend that they be used as rat deterrents, as there are now safer and more effective alternatives.
Check out this related video from Homesteady on Youtube.