/

How to Run JavaScript Snippets Easily

How to Run JavaScript Snippets Easily

When it comes to testing or experimenting with JavaScript code, there are several convenient tools that I rely on. These tools make it easy to run little snippets of JavaScript and quickly see the results.

One simple method is to open a Chrome or Firefox DevTools window and type your code there. This is perfect for trying out a line or two, but can be cumbersome if you need to spend more time on the code. For example, if you declare a constant value, you need to refresh the window to re-run it.

Another useful tool is the Quokka.js extension for VS Code. This extension allows you to test JavaScript snippets directly in your editor. It provides a convenient way to experiment and see the results of your code in real-time.

Additionally, I often use RunJS, a small Electron application that allows you to type code on the left and immediately see the results on the right. Unlike other tools, RunJS evaluates the code as you type, eliminating the need to press a “run” button or encounter any roadblocks while trying things out. It also supports both browser and Node.js code, making it a versatile choice.

In RunJS, you have the ability to import Node modules by setting a working directory where it can find them in a node_modules folder. Alternatively, you can install npm packages directly from the “Action -> Install NPM packages” menu. RunJS even supports TypeScript and Babel, adding further flexibility to your testing process.

Although currently limited to macOS, similar tools are available for Linux and Windows users. So, regardless of your operating system, you can find a suitable tool to run JavaScript snippets conveniently.

Tags: JavaScript snippets, code testing, DevTools, Quokka.js, RunJS, Electron application, VS Code extension, code experimentation