Custom:button-card, javascript & variables

I have the following issue with variables & javascript on a custom:button-card.

In the ‘variables’ section the following code works fine:

    R: |
      [[[
        {
          var n = (entity.state * 1.27 / 5580) * 100;
          return ((255 * (100 - n)) / 100) | 0;
        }
      ]]]
    G: |
      [[[
        {
          var n = (entity.state * 1.27 / 5580) * 100;
          return ((255 * n) / 100) | 0;
        }
      ]]]

But when I replace the dividing value by a variable, it doesn’t:

    d: 5580
    R: |
      [[[
        {
          var n = (entity.state * 1.27 / variables.d) * 100;
          return ((255 * (100 - n)) / 100) | 0;
        }
      ]]]
    G: |
      [[[
        {
          var n = (entity.state * 1.27 / variables.d) * 100;
          return ((255 * n) / 100) | 0;
        }
      ]]]

What am I missing?

Found the solution:
There is a bit of misleading info in the readme.md:

Variables are evaluated in their alphabetical order based on their name. That means a variable named b can depend on a variable named a, but variable named a can’t depend on a variable named b.

This needs to be supplemented with: ASCII order.
I was using caps / noncaps varnames. Since the capitals are the first to appear in the ASCII table, they are evaluated first.
Meaning that the noncaps varnames remain undefined until the caps varnames are processed.

Basically the code was outputting

    d: 5580
    R: |
      [[[
        {
          var n = (entity.state * 1.27 / **undefined**) * 100;
          return ((255 * (100 - n)) / 100) | 0;
        }
      ]]]