Chrome: Call Javascript function from (system) command line?
After some more research I found crconsole, which can be used to execute code in Google Chrome.
Chrome has to be started like this:open -a "Google Chrome" --args --remote-debugging-port=9222
The command line utility chrome-cli can do this.
Using your code example:
chrome-cli execute '(function hello() { alert("hello"); }())'