Background Variability of vascular risk factors (VRFs) is linked to increased dementia risk. Whether midlife depression, smoking, hypertension, diabetes, obesity, and dyslipidemia modify the association between VRF variability from childhood and midlife cognitive function (CF) is unclear. Methods Bogalusa Heart Study participants with ≥ 3 repeated measurements of systolic blood pressure (SBP), glucose, non-HDL, and BMI across the life course and one midlife CF assessment were included. CF was evaluated using the global cognitive score (GCS), derived from averaging eight standardized neuropsychological test scores. VRF variability was assessed using coefficient of variation. Associations between VRF variability and GCS were examined using multivariable linear regression models stratified by depressive symptoms (10- item Center for Epidemiologic Studies Depression scale ≥10), smoking status, hypertension, T2DM, dyslipidemia, and obesity. Results A total of 1,010 participants were evaluated (34% Black, 61% women; mean age 48 years; follow-up 39 years). Higher glucose variability was associated with poorer GCS among individuals with hypertension (highest vs. lowest tertile, β = -0.12, 95% CI -0.22, -0.02), and among those without depression, obesity, dyslipidemia, diabetes, and among never smokers. Higher SBP variability was associated with poorer GCS only among former smokers (highest vs. lowest tertile, β = -0.16, 95% CI -0.30, -0.02). Middle-tertile BMI variability was associated with better GCS among individuals without depression, without diabetes, and among never smokers. Middle-tertile non-HDL variability was associated with poorer GCS only among individuals without depression. Conclusions Tracking VRF variability from early life even in low-risk populations could facilitate optimal cognitive aging.