I have such code:
<body>
<script>
window.nix = window.nix || {} ;
nix.falkorCache = 1;
</script>
...
I want to get nix variable with jQuery.
How can I access it?
As you wrote it, it should work. Anything assigned to window can be accessed as if it were a top-level value, i.e.,:
console.log(nix.falkorCache); // should work
If it's telling your that nix is undefined, the most likely culprit is that you are trying to access it before it is there.
In your HTML, that segment of code should be above any code that tries to access it, i.e.:
<body>
<script>
console.log(nix.falkorCache); // bad
</script>
<script>
window.nix = window.nix || {};
nix.falkorCache = 1;
</script>
<script>
console.log(nix.falkorCache); // good
</script>
That's the most likely culprit for your problem is just having it in the wrong order. If you're pulling in a <script> tag, you should put it at the bottom of your body element.
If that doesn't work, a few less likely culprits are:
nix to null or undefined in between the two.<iframe> or something.window.nix = window.nix || {}; nix.falkorCache = 1; creates after the page load. Could it be the reason why the variable is not accecable?
nixorwindow.nix), there is nothing jquery-specific about it.window.nix.falkorCacheI seeCannot read property 'falkorCache' of undefinednix.falkorCachecreates after the page load. Can it be the problem with trying to access it?