<script> function foo() { window.yourGlobalVariable = ...; } </script>
globalThis.yourGlobalVariable = ...;