Uibuilder - passing variables from node-red to frontend

Imagine the following in a webpage;

<script>
    var myvar = 'foobar';
</script>

Now I would like to change that variable from Node-red - uibuilder. Is there a way to do this?
I have reviewed much of the documentation and videos and most of it concerns inserting and updating sections of the webpage that are visible.

Can I send a variable from Node-red or modify a variable that already exists?

Have faith! There is always a way with UIBUILDER. :smile:

Absolutely. Here is the classic method:

let myvar = 'foobar'
uibuilder.onChange('msg', (msg) => {
  myvar = msg.payload
})

You could also use onTopic instead of onChange if you prefer.