Global variables are an absolute no-go.
End of post?
No, of course not. But there is one nagging detail in ECMAScript that allows for so called implied global variables. You can get them quite easily, just forget to add a declaration
I don’t think there is a solution for it. You can try JSlint but it is a it behind, closed-source (or I just couldn’t find it) online, so one does not know what happens to your data.
But that rant was just a digress, not what I wanted to talk about.
Now, global variables are a real problem. Webworker are a very primitive form of threads, as mentioned above, so none of the useful things from e.g.: the Posix threads exist. You can start it, end it, send messages to it and let it send messages to you. You can only send one
Object as it seems but that is enough as you can use JSON or equivalent to tie up a parcel, pardon
Now what to do with global variables; how to get and more so how to set them concurrently?
The Posix threads have a couple of quite nasty but very useful things to handle that, Web-Workers don’t. The don’t know anything about shared memory, they just don’t have shared memory. Webworkers are just some glorified processes.
If you need only small amounts of shared memory, say up to 2.5 MB than you can make use of some of the small external storages the new ECMAScript offers, for example
localStorage, although it can only save strings.