Run Javascript on Mac Terminal

You can run your Javascript code on your MacOS terminal easily.

1. Add an alias to your .bashrc or .zshrc

[code lang="bash"]

alias jsc="/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc"

[/code]

2. Reload your .bashrc or .zshrc

[code lang="bash"]

source ~/.zshrc // or source ~/.bashrc

[/code]

3. Write codes

[code lang="javascript"]

// hello.js

print("Hello World");

[/code]

4. Run jsc

[code lang="bash"]

jsc hello.js

[/code]

What a handy!