Node.js has an -e
commandline switch to evaluate code provided on the commandline rather than in a separate script file.
Oddly, I can't find official documentation for it online but the node executable self-documents it if you run node --help
:
>node --help
Usage: node [options] [ -e script | script.js ] [arguments]
node debug script.js [arguments]
Options:
-v, --version print Node.js version
-e, --eval script evaluate script
-p, --print evaluate script and print result
Now there are several ways to use Unicode literals in JavaScript, all seemingly begin with \u
.
But no matter how I try to quote or escape the string with the Unicode literal, the code always fails to execute. Both under official Node.js and also JXcore.
Node
>node -e console.log('hello \u00A9')
[eval]:1
console.log('hello
^^^^^^
SyntaxError: Unexpected token ILLEGAL
at Object.exports.runInThisContext (vm.js:53:16)
at Object.<anonymous> ([eval]-wrapper:6:22)
at Module._compile (module.js:435:26)
at node.js:578:27
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
JXcore
>jx -e console.log('hello \u{00A9}')
SyntaxError: unterminated string literal ([eval] 1:12)
at ([eval]-wrapper:6:8)
at Module.prototype._compile (module.js:621:10)
at evalScript (node.js:1054:18)
at startup (node.js:419:7)
at node.js:1604:3
I've tried double \\
and quadruple \\\\
. I've tried single and double quote characters to delimit the strings.
(I am only trying this under Windows, just in case this might work fine under *nix.)