You can run the JavaScriptCore Framework from the CLI to run javascript code.
All we have to do is create an alias to access the jsc binary easily from the CLI.
sudo ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/Current/Resources/jsc /bin/jsc
To see the CLI options available visit the WebKit wiki. http://trac.webkit.org/wiki/JSC
Also using brew you can install spidermonkey.
brew install spidermonkey
Javascript with Automator, shell and Apple's Open Scripting Architecture https://github.com/dtinth/JXA-Cookbook/wiki/Using-JavaScript-for-Automation https://developer.apple.com/library/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/
http://www.freshblurbs.com/blog/2011/09/25/command-line-javascript-cli-mac-os-x.html
Thank you, this works for me