In The Virtue of Selfishness, Ayn Rand wrote,
Just as the pleasure-pain mechanism of man’s body is an automatic indicator of his body’s welfare or injury, a barometer of its basic alternative, life or death—so the emotional mechanism of man’s consciousness is geared to perform the same function, as a barometer that registers the same alternative by means of two basic emotions: joy or suffering. Emotions are the automatic results of man’s value judgments integrated by his subconscious; emotions are estimates of that which furthers man’s values or threatens them, that which is for him or against him—lightning calculators giving him the sum of his profit or loss.
But while the standard of value operating the physical pleasure-pain mechanism of man’s body is automatic and innate, determined by the nature of his body—the standard of value operating his emotional mechanism, is not. Since man has no automatic knowledge, he can have no automatic values; since he has no innate ideas, he can have no innate value judgments.
Man is born with an emotional mechanism, just as he is born with a cognitive mechanism; but, at birth, both are “tabula rasa.” [“blank slate”] It is man’s cognitive faculty, his mind, that determines the content of both. Man’s emotional mechanism is like an electronic computer, which his mind has to program—and the programming consists of the values his mind chooses.
But since the work of man’s mind is not automatic, his values, like all his premises, are the product either of his thinking or of his evasions: man chooses his values by a conscious process of thought—or accepts them by default, by subconscious associations, on faith, on someone’s authority, by some form of social osmosis or blind imitation. Emotions are produced by man’s premises, held consciously or subconsciously, explicitly or implicitly.
Man has no choice about his capacity to feel that something is good for him or evil, but what he will consider good or evil, what will give him joy or pain, what he will love or hate, desire or fear, depends on his standard of value. If he chooses irrational values, he switches his emotional mechanism from the role of his guardian to the role of his destroyer. The irrational is the impossible; it is that which contradicts the facts of reality; facts cannot be altered by a wish, but they can destroy the wisher.
Here Miss Rand is referring to the specifically human form of emotion. But let’s start with the most basic form in which emotions manifest: in non-human animals.