How to set CSS custom property in JavaScript

DOM
Last updated Mar 12, 2018
:root {
  --primary-color: #ececec;
}
document.documentElement.style.setProperty("--primary-color", "#000000");