Why is an all-nighter a self-defeating way to prepare for an exam?
Because it sacrifices the exact sleep-dependent consolidation that would have locked in what you studied — you trade the mechanism that saves the material for a few extra hours of cramming.
Sleep amplifies learning that already happened; it cannot encode what you never studied. Staying awake to cram more feels productive, but it removes the overnight replay that would have moved the day's material into durable storage — and it leaves you cognitively impaired the next morning, hurting retrieval and reasoning during the test itself.
The better pattern: study important material in the evening, sleep on it, and do a quick recall the next morning. You let consolidation run overnight and then verify what stuck — using sleep as a partner rather than a resource to strip-mine.