If you really wanted to, you could simulate this behavior in threaded languages by having a global lock you acquire before you run anything.
It's the python GIL problem [1]
Languages like kotlin, rust, C++, or C# with async/await MUST concern themselves with locks because they don't acquire whole application locks anytime they run a sliver of code.
But if you don't, then yeah, you sort of run right into the need for an actual lock since you can have shared memory in concurrently executing interpreters. Entire: Web Lock [1] Specifically designed to resolve this issue.
In typical JS programming this is not an issue, but if you are trying to really abuse that javascript VM then this is the way you'd do it.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_A...