CuteMachine

How To Run JavaScript Code Snippets

When we learn about new JavaScript features or packages, it is always a good idea to play around with it. For this, we do not want to bootstrap a new project. A better approach is to use a JavaScript REPL (Read Eval Print Loop).

Jay—Supercharged JavaScript REPL

Jay is a terminal-based JavaScript REPL focused on increasing prototyping speed and productivity. It's packed with modern REPL features, whilst also striving to maintain a familiar REPL vibe.

For some time, I used Jay, but it seems that the project is no longer maintained, though it still works.

You can install it through NPM.

$ npm install -g jay-repl
$ jay

Quokka—Live Scratchpad For JavaScript

Rapid JavaScript Prototyping In Your Editor

Another popular option for Visual Studio Code users is Quokka. Quokka is a rapid JavaScript prototyping environment. Unfortunately, the Quokka VSCode plugin does not work well with the Vim emulation (vscodevim) I'm using. So this was no option for me, but if you do not use Vim, it might be an excellent option to satisfy your needs.

There is a community and a pro edition available. If you want to install packages, you need to switch to the pro plan.

And The Winner Is RunJS

RunJS by Luke Haas is the best JavaScript REPL I have found. The application is available for Windows, Linux, and macOS. And I was pleasantly surprised when I saw that you could enable vi-style editing in the settings, which is fantastic.

RunJS

One excellent feature of RunJS is that you can install npm packages. For example, if you want to install the JavaScript utility library Lodash, you can press command-i, search for the package, and install it with a click of a button.

RunJS Package Imports

You can then import it like you usually would.

import without from 'lodash/without'

without([1, 2, 3], 2)    // [ 1, 3 ]

Conclusion

There are many options available when you want to quickly try a new JavaScript feature or want to play around with an npm package without having to bootstrap a suitable environment.

There are many more browser-based solutions. What are you using? Let me know via Twitter.

Posted on CuteMachine.

Jo's Profile ImageWritten by Jo who lives and works in Frankfurt building digital doodah. Stalk him on Twitter.

TOS • Privacy • Disclaimer