For a long time it was believed that dark complexion evolved to protect humans from skin cancer. However, this theory has a flaw: melanoma typically is contracted after the reproductive age. Hence, the traditional theory for complexion cannot be correct because melanoma does not impact evolution.
Recently Nina Jablonski has hypothesized that like chimpanzees, our ancient ancestors in Africa originally had fair skin covered with hair. When they lost body hair in order to keep cool through sweating, perhaps about 1.5 million years ago, their naked skin became darker to protect it from folate-destroying UV light.
Neural tube birth defects such as spina bifida are linked to deficiencies in folate, a naturally occurring form of vitamin B; Nina Jablonski learned that sunlight can destroy folate circulating in the tiny blood vessels of the skin. Furthermore, lower vitamin D weakens the immune response to the mycobacterium that causes tuberculosis. With this there is a strong evolutionary explanation for complexion variation.
If you live in a Silicon Valley hacker dojo or wear a burka, do not forget your vitamin B pills!