Why does calling a function in the Node.js REPL with )( work?

Why is it possible to call function in JavaScript like this, tested with node.js:

~$ node
> function hi() { console.log("Hello, World!"); };
undefined
> hi
[Function: hi]
> hi()
Hello, World!
undefined
> hi)( // WTF?
Hello, World!
undefined
>

Why does the last call, hi)(, work? Is it bug in node.js, bug in V8 engine, officially undefined behaviour, or actually valid JavaScript for all interpreters?

3 Answers
3

Leave a Comment