Acessando uma propriedade customizada CSS (também conhecida como variável CSS) por meio de JavaScript

Como você obtém e define propriedades personalizadas de CSS (aquelas acessadas comvar(…) na folha de estilo) usando JavaScript (comum ou jQuery)?

Aqui está a minha tentativa malsucedida: clicar nos botões muda o habitualfont-weight propriedade, mas não o costume--mycolor propriedade:

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <style>
    body { 
      --mycolor: yellow;
      background-color: var(--mycolor);
    }
  </style>
</head>
<body>

  <p>Let's try to make this text bold and the background red.</p>
  <button onclick="plain_js()">Plain JS</button>
  <button onclick="jQuery_()">jQuery</button>

  <script>
  function plain_js() { 
    document.body.style['font-weight'] = 'bold';
    document.body.style['--mycolor'] = 'red';
  };
  function jQuery_() {
    $('body').css('font-weight', 'bold');
    $('body').css('--mycolor', 'red');
  }
  </script>
</body>
</html>

questionAnswers(3)

yourAnswerToTheQuestion