JavaScript Console without browser
Ever wanted to run/test/debug JavaScript in console without having to launch your web browser? Well, now you can!
Run this line of code in your terminal and you’re good to go (just make sure /opt/local/bin is in your PATH system variable):
sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /opt/local/bin
Restart your Terminal, and type jsc --help:
$ jsc --help Usage: jsc [options] [files] [-- arguments] -d Dumps bytecode (debug builds only) -e Evaluate argument as script code -f Specifies a source file (deprecated) -h|--help Prints this help message -i Enables interactive mode (default if no files are specified) -s Installs signal handlers that exit on a crash (Unix platforms only)
You can eval piece of code when running console:
$ jsc -i -e 'function foo(arg){return arg ? arg+"ed!" : "bar!";}' -i
> foo()
bar!
> foo("baz")
bazed!
or even eval whole files (test.js contains foo() function from above)
$ jsc -i test.js
> foo("k'")
k'ed!
That’s it. Have fun!