Back at times of the Roman Empire, people already used fasting to treat neurological diseases without knowing it. They thought that somebody with epileptic seizures were possessed by demons and they found if they take these people and shut them in a room without food, the demons would disappear.
What happened was that through the fast, blood ketone body level went up and suppressed the seizures.
Nowadays, fasting and the ketogenic diet is used to treat epilepsy.
Hippocrates was one of the first to understand that epilepsy was nothing supernatural but and indicates in one of his works that the epileptic patient's body is “polluted” and can be purified through diet. [2,3]
More recently, fasting or fasting mimicking diets have emerged as powerful tools to prevent and treat neurodegenerative diseases. A study published this year found that "Intermittent fasting protects against the deterioration of cognitive function" 
Fasting increases BDNF levels in the brain
For most people fasting is not just a way of preventing neurodegenerative diseases like Alzheimer's but also to boost the brain and when it comes to boosting the brain, the most studied protein in this field is the Brain-derived neurotrophic factor.
BDNF itself is important for learning, long-term memory, and plays a role in neurogenesis, which is the new formation of neurons.
Throughout aging, the levels of BDNF decrease and patient with Alzheimer’s disease have generally lower levels of BDNF. Therefore, it might be a good idea to keep you BDNF levels up. 
Researchers looked into the effects of fasting on BDNF levels in specific regions of the brain. Therefore, mice were placed on an every-other-day fasting regime for three months and their BDNF levels were compared to mice that had unlimited access to food. The scientist found that in regions of the hippocampus, which is the center that plays important roles in the consolidation of information from short-term memory to long-term memory, the levels of BDNF were actually increased 3-fold. 
However, it is important to point out that the same research group published in another paper that intermittent fasting in rats did show an increase of BDNF levels in the cortex and hippocampus of “only” approx 40%. 
The explanation the research group provides is that the higher increase was seen when they took very specific parts of the brain regions. Parts were they thought neurogenesis is happening and therefore BDNF levels should be increased.
By increasing the levels of BDNF, fasting also increases the number of mitochondria in the nerve cells. And a paper from 2012 showed that by increasing the number of mitochondria in the neurons, it increases the ability to form and maintain synapses, which are important for learning and memory. 
Chronic inflammation is another risk factor for cognitive impairment and dementia. A molecule that is used to initiate inflammatory reactions in laboratory settings is lipopolysaccharide (LPS). It is a molecule found at the cell wall of bacteria and usually it should not be inside our blood stream. However, if you have a severe infection or a condition called leaky gut, bacteria rush into your blood and induce strong immune reactions.
In research, LPS is mostly used to induce a variety of diseases via an overstimulation of the immune sytsem:
LPS was used to generate a rat model for Alzheimer’s disease 
LPS has also been shown to induce anxiety and depressive-like behaviors in mice 
New studies connect LPS to the development of Multiple Sclerosis 
There are ways to protect your body from inflammation and besides keeping your microbiome healthy, intermittent fasting seems to be very powerful tool to reduce inflammation levels in the body.
A research group from Sao Paulo found that that Intermittent fasting attenuates lipopolysaccharide-induced neuroinflammation and memory impairment . The scientist placed rats on an alternate day feeding schedule and injected them with LPS, which led to memory impairment in the control rat group on a normal feeding schedule but was prevented through IF. They found that IF actually reduced the levels of inflammatory proteins in the brain of the rats and that it prevents (LPS)-induced depletion of hippocampal brain-derived neurotrophic factor.
It is not yet completely clear why fasting increases the expression of BDNF but Dr. Mattson, Professor of Neuroscience at Johns Hopkins University, explains it like this:
”Fasting is a challenge to your brain and the brain and your brain response to that challenge of not having food by activating adaptive stress response pathways that help your brain to cope with stress and resists disease” 
It is like exercise for the brain. If you work out, it is also a stress for your muscles, which tells them to become stronger.
One of the leading hypothesis in this field is that the ability to think more efficient and become more clear minded when not having food, gave the early human a survival benefit. In biology, everything is viewed in the context of evolution and becoming "smart" and focused in an environment where food is rare could mean to survive.
Take Home Message:
Fasting can be beneficial to the brain and has the potential to prevent neurological diseases!
Lennox WG, Lennox MA. Epilepsy and related disorders, vol. 2. Boston: Little, Brown; 1960.
Hippocrates. The genuine work of Hippocrates; translated from the Greek by Francis Adams. Baltimore, Williams and Wilkins, 1939, 368–9
Shin et al., Intermittent fasting protects against the deterioration of cognitive function, energy metabolism and dyslipidemia in Alzheimer’s disease-induced estrogen deficient rats, Experimental Biology and Medicine, 2018
Tapia-Arancibia et al., New insights into brain BDNF function in normal aging and Alzheimer disease., Brain Res Rev, 2008
Lee et al., Evidence that brain-derived neurotrophic factor is required for basal neurogenesis and mediates, in part, the enhancement of neurogenesis by dietary restriction in the hippocampus of adult mice, Journal of Neurochemistry, 2002
Lee et al., Dietary restriction increases the number of newly generated neural cells, and induces BDNF expression, in the dentate gyrus of rats, Journal of Molecular Neuroscience, 2000
Cheng et al., Involvement of PGC-1a in the formation and maintenance of neuronal dendritic spines, Nature Communications, 2012
Zakaria et al., Lipopolysaccharide-Induced Memory Impairment in Rats: a Model of Alzheimer’s Disease, Physiol Res, 2017
O'Connor et al., Lipopolysaccharide-induced depressive-like behavior is mediated by indoleamine 2,3-dioxygenase activation in mice, Mol Psychiatry, 2009
Escribano et al., Lipopolysaccharide Binding Protein and Oxidative Stress in a Multiple Sclerosis Model, Neurotherapeutics, 2017
Vasconcelos et al., Intermittent fasting attenuates lipopolysaccharide- induced neuroinflammation and memory impairment, Journal of Neuroinflammation 2014
Dr. Mark Mattson - Ted Talk: https://www.youtube.com/watch?v=4UkZAwKoCP8