I'm afraid that's just not how JavaScript works. You could probably implement something with callbacks, but JavaScript wouldn't normally work like that.
There's an online 'command prompt' type example here that uses your Web Browser's JS engine: http://www.jsconsole.com/
It's an easy way to see what kind of things it can do.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I'm afraid that's just not how JavaScript works. You could probably implement something with callbacks, but JavaScript wouldn't normally work like that.
There's an online 'command prompt' type example here that uses your Web Browser's JS engine: http://www.jsconsole.com/
It's an easy way to see what kind of things it can do.