I didn't explore this too much but yes the above code is what I had originally tried. When running it I got some error (can't remember exactly) like "lost prompt" and then nothing.
Having it outside fails to connect to the web site until the WiFi is connected but otherwise works.
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.
Copying your code together this would be the code not working, right?
And having the exact same promise definition "var clearQueuePromise =" outside of the "wifi.on('connected')" makes it work?