ES6 Playgrounds: Run and test ECMA Script 6 online, in terminal or using plugins

Mon Aug 10 2015

Paul Shan

ECMA Script 6 is probably the most talked topics in the JavaScript world today. The feature set draft is almost frozen. Many of those features are appearing in the browsers slowly but steadily. Many blogs have already covered all those upcomming awesome features of ES6. But how to test, experiment and play with your ECMA 6 code at this point of time when most of the features are not available on browser by default? This article contains some of the good solutions for this.

Online playgrounds:

Though browsers don't have full support for ES6, but there are few tools which converts your ES6 codes to equivalent ES5 vanilla code; which runs fine in browsers. The online playgrounds below does the same and help you to test ES6.

Babel

babel repl

Babel Repl is a playground for ECMA script 6; where you can write ES6 code, check the relevant code in ES5; and also the output. Babel is probably the best and easiest solution to test your ES6 code today.

Traceur

traceir repl

Traceur is a product by Google. It provides an online repl too to experiment with ES6. Unlike Babel, here you need to open your developers tool's JavaScript console to see the console output.

Command line solutions:

You can also test ES6 in your command prompt or terminal. Just like using the node command. Few of the solutions are given below.

babel-node

Babel also has a npm module; installing which you can easily rum ES6 codes in your command window. Below are the steps to make your terminal ready for ES6 with babel.

$ npm install --global babel

$ babel-node
// write your ES6 code here

traceur-cli

Traceur provides a command line interface too for experimenting with ES6 codes. The name of the npm module is traceur-cli. Below are the steps.

$ npm install --global traceur-cli

$ traceur-cli
traceur> //write your code here

ECMA Script 6 on browsers

Though browsers don't have full support of ES6, but they have started implementing the same. You can find which browser support what features of ES6 from here.

Run ES6 on Mozilla Firefox

Open firefox developer tools and you can test certain ES6 properties/features of ES6.

es6 in firefox

Run ES6 on Google Chrome

Chrome's experimental JavaScript features are disabled by default. To play with ES6 code in Chrome you have to enable Experimental JavaScript from chrome://flags/ Once you enable it and restart chrome, you will be able to test your ES6 code in Chrome console (only the features implemented by chrome). However, most of the features are reserved for only "scrict mode". So, you have to run your code in scrict mode only. Below is a code example to run in strict mode.

(function(){
  "use strict";

  let x = 10;

  function testX(condition){
    if(condition){
      let x = 1;
    }
    return x;
  }

  console.log("Condition true output: "+testX(true));

})();

Scratch JS

Scratch JS is a browser extension available for Chrome and Opera. This plugin internally uses Babel and Trecure (you can select any of them from the setting of that plugin) and runs your script right there in your developer tools.

scratch js browser

Now why to use a plugin when we can directly use babel or traceur from their site itself? The answer is, generally developers read some blog and try to test their JavaScript code right there opening up the developers tools. Using Scratch JS, you can keep going with this habit of yours, even for ES6.

SHARE THIS ARTICLE

post-thumbnail
Today everyone knows the importance of a lightning-fast website and how the speed impacts the conversion rate of a business. Today, everyone wants the site to be a PWA so that the mobile users can have an app-like experience with the website because, for the majority of the merchants, the customers come through mobile devices.
Tue Apr 20 2021
post-thumbnail
Here we are going to see how you can manage backup and restore of Postgres database with docker.
Thu Sep 03 2020
post-thumbnail
Image sliders or carousels always have increased the UI attraction of websites and they are pretty useful for reflecting the major roles/products too. In case, I am having a website that sells tee-shirts,
Mon Apr 30 2018

About VoidCanvas

This blog was created out of hobby and talks mostly about technology, web development, JavaScript, NodeJS and related topics. Thank you for reading my blog.

Copyright 2022 - www.voidcanvas.com

Popular Articles

Authentication using Google's oAuth api with node.js

Thu Mar 10 2016

OAuth authentications are pretty popular now a days and another thing which is popular is JavaScript. This article shows how to plugin google’s oAuth api for authentication in your own node application.

CSS3 Loader Snippet Collection: (Part 2 - Squares)

Sat Mar 01 2014

This is a continuation of my CSS3 loader snippet collection series. I've provided spinning css3 animation loader in the part 1 of this series and here in part 2, I'm providing various square type loading