About Sass Variables in JavaScript

You can pass Sass variables to JavaScript using CSS custom properties as follows:

Sass:

1
2
3
4
5
$theme_color: #215a00;

:root {
    --theme-color: #{$theme_color};
}

JavaScript:

1
2
const themeColor = getComputedStyle(document.body)
    .getPropertyValue('--theme-color');

Tips and Tricks Programming JavaScript CSS3 Sass