Nitric oxide affects cognitive function by facilitating neurotransmission, which is crucial for memory, learning, and brain health.