A porcupine carries something on the order of 30,000 quills, which are modified hairs stiffened with keratin. They lie flat until the animal is alarmed, when muscles at the skin raise them into a barrier. The defence is contact-based: the porcupine turns its back, chatters its teeth and lashes with its tail, and quills that touch skin pull free from their own follicles.
The tip carries backward-facing barbs, microscopic scales layered along its last few millimetres. Studies of quill mechanics have shown that these barbs cut penetration force substantially on entry while sharply increasing the force needed for withdrawal, so the quill works its way inwards with the victim's own muscle movement.
The throwing myth probably comes from how easily loose quills fly off a shaking animal. It is also worth noting that quills are not venomous, though embedded ones frequently cause infection and, in dogs and coyotes, occasionally migrate into internal organs.
