Yepp, that's working as it should work. You would get the same result in every other environment with the same escaping rules. Just try it in a browser console :) \n is just a way to write newline character.
To get foo\nbar\\nfoo you should write foo\\nbar\\\\nfoo.
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've stripped down my code, same error: