Home » Odeon Blogs » Michelle Chan »

Javascript in Shell

Javascript in Shell

I used to test out Javascript in browsers' console. But I just found a way to run it in my Terminal.


No installation! There is JavascriptCore in Mac OS X called jsc, which is in /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc. 

So I created a soft link to /bin :

  1. ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc /bin/jsc

Let's test JSC in your terminal,

  1. $ jsc
  2. > "hello world"
  3. hello world
  4. > [] + {}
  5. [object Object]
  6. > {} + []
  7. 0
  8. > Array(16).join("haha" - 1)
  9. NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
  10. >

Enjoy... 


Categories: Javascript OS X


Tagged as: Javascript Terminal

Discussion

  1. the example works for my ibook and my ubuntu! thank you for sharing!


  2. jesse on May 24, 2012 - 22:49 said:

    Is there any "jsc" in ubuntu ? Where did you find it ?

    It works on my imac, Thanks


  3. Fletch Hasues on Mar 04, 2013 - 6:36 said:

    If one installs the spidermonkey package, it will provide the "js" executable on Linux platforms.




Leave a Comment :

(required)


(required)




(required)








Page generated in: 0.14s