It’s like this:
<script>
var global_var = {foo:1};
</script>
<script src="myscript.js"></script>
in myscript.js I have
jQuery(document).ready(function($){
var global_var = typeof global_var == 'undefined' ? {foo:2} : global_var;
console.log(global_var);
});
But the global_var does not seem to be recognized in my 2nd script, even though I clearly defined it in the first, like a global variable.
The problem is the “var” in “var global_var” within your jQuery function. This is creating a different “global_var” variable within your function instead of using the true global. Drop this and your code works as expected.