Which board/firmware are you using? It would probably help to have the complete bit of code too.
@Gordon started
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.
Which board/firmware are you using? It would probably help to have the complete bit of code too.