Compile to JavaScript: The 10 Best JavaScript Alternative Languages

10 min read
Updated: Sep 16, 2019

Write JavaScript code once and run it anywhere, in any browser, on any platform. That is the current state of affairs with JavaScript, which is ruling the world of web development as well as mobile apps development.

Whether it is about client side programming, server side programming or mobile native interfaces, JavaScript is everywhere.

Why do we need JavaScript alternative languages?

When Brendan Eich designed JavaScript to run in Netscape browser, at that time, he may never have thought about unprecedented growth of JavaScript even in his dreams.

The core package of JavaScript is not that great and comes with many challenges, the biggest of which is the core design of JavaScript itself that doesn’t give us enough space to write manageable and scalable JavaScript with ease.

To overcome flaws and limitations of base JavaScript, many alternate programming languages mushroomed including CoffeScript and Typescript that compile to JavaScript, in the end.

Why Compile to JavaScript?

That is because web browsers were designed to run JavaScript only, and over the period of time, JavaScript became the undisputed standard for browser based programming. Browsers come with inbuilt JavaScript runtime engine which is based on ESMA script.

We can also say that once browsers started supporting JavaScript, one after the other, there was never a turn back. We never got to the point where we could say that let us drop JavaScript and/or shift to something else, something better or differently designed.

Though browsers were the gateway to JavaScript growth but with advent of node.js, JavaScript started to rule the server side programming, too.

Further to JavaScript growth was the arrival of modern age hybrid apps development platforms that took JavaScript to the new heights and into the mobile apps development arena.

What Languages Compile to JavaScript?

There is no dearth of JavaScript alternative languages and it can be a tedious task to analyze and select the one for your programming needs. Here is an attempt to make the selection process a little easier.

I have tried to review most of the modern programming languages that compile to JavaScript and listed below are the ones that do the job with elegance and are loved by developers all around.

1. CoffeScript

CoffeScript is the most widely used language as an alternative to JavaScript. It has the biggest following on GitHub among all of its competitors. CoffeScript is the creation of Jeremy Ashkenas who released the very first draft of CoffeScript back in 2009 under MIT license, as open source.

CoffeScript takes inspiration from Ruby and Python and you can smell the taste of Ruby and PHP in CoffeScript code. CoffeScript compiles to neat and clean JavaScript, existing JavaScript can be included as-is in CoffeScript.

CoffeScript grew in width and breadth ever since its release and made such an influence on Ruby language community that it is now supported out of the box in Ruby on Rails. CoffeScript is more of what JavaScript is in terms of features, but eases out the way we write script by allowing neat function declarations, no mandatory curly braces, meaningful white space as in Ruby, optional parentheses etc. to name a few.

CoffeScript can run in any environment where JavaScript can run and is available as npm package, you can download, install and run CoffeScript locally in the node server.

CoffeScript Vs TypeScript: I often get this request to do a comparison between CoffeScript and TypeScript. My simple answer to that is “CoffeScript is for masses and TypeScript is for classes”. TypeScript is covered next.

Read more about CoffeScript at official website – coffeescript.org.

2. TypeScript

Typescript is the creation of Anders Hejlsberg of Microsoft and is the most intuitive alternative to JavaScript. Hejlsberg comes from the world of C#, which is the most powerful language for enterprise grade application development. You will find glimpses of C# in Typescript.

Typescript is essentially a superset of JavaScript and adds superpowers to JavaScript with additional features like types, classes and modules to name a few. Typescript also supports interfaces and namespaces that help you write maintainable and scalable code for complex and large scale applications.

The best thing about Typescript is that you can write JavaScript, copy existing JavaScript, and build on top of it using enhanced features that it brings. This allows you to utilize existing JavaScript libraries and frameworks in your TypeScript project.

If you want to evaluate or just play around with Typescript without setting it up on your machine, you can do that here at TypeScript playground.

Read more about Typescript at official website – typescriptlang.org.

3. Babel

JavaScript is based on ECMAScript and the current most supported version of ECMAScript is ES5, some of the recent browsers support ES6, too, in beta. There are many enhancements lined up in 6th Edition of ECMAScript which will add superpowers of the likes of CoffeScript and TypeScript to core JavaScript itself.

We want to make JavaScript elegant with upcoming  releases of ECMAScript but changing the entire ecosystem is not an easy task. ECMAScript 6 is yet not widely supported (as of writing this article), not stabilized and there is no support available in browsers to run JavaScript based on ECMAScript6.

Do we have to wait for that? Not Really!!

Babel is the compiler that converts ES6+ JavaScript code to ES5 compatible JavaScript code. This is the biggest advantage, you write JavaScript of the future right now and when the new JavaScript features get released you are way ahead in the game. You don’t have to wait for the browser support. You do not have to learn any other scripting language like TypeScript or CoffeScript, you just write JavaScript which is 100% future proof.

Babel also comes packed with react.js support and in built JSX transformation engine. Babel-Sublime package would power up the syntax highlighting in sublime text. Babel is distributed as open source under MIT license and available for free public use. Babel runs on Jade template engine and is available as npm package.

Read more about Babel at official website here – babeljs.io.

4. ELM

ELM is an interesting space and that is the reason to include it in this list despite the fact that it is not a pure JavaScript compiler.

ELM compiles to HTML, CSS and JavaScript and is most suitable for building complete apps or websites rather than compiling to just JavaScript. ELM is a functional reactive language that ensures fast rendering which is the backbone of interactive applications, best suited for 2d, 3d games and animations.

You can read more about ELM at – elm-lang.org.

5. Haxe

Haxe is the master of all trades, the big daddy of all the compilers I know till date. You can look at Haxe as an open source toolkit which is based on strictly typed modern programming paradigm. It can compile to different languages including JavaScript as well as can access native capabilities of platforms like iOS and Android.

Haxe compilers compile to the native code of almost all platforms and that too without compromising with the performance. The compiled code runs directly in the native platforms without the need of virtual machine runtimes.

Haxe as a whole consists of

  •  – Programming language
  •  – Haxe Cross Compiler
  •  – Haxe Standard Library
  •  – Haxe based Frameworks and Tools

Haxe is used by developers and enterprises across the globe for developing cross platform games, apps, frameworks and tools.

You can read more about Haxe here at – haxe.org.

6. Traceur

The concept of Traceur is much like that of Babel i.e. to start using next generation of JavaScript right today. Traceur supports all of the ES6 features and other experimental features of JavaScript.

Traceur compiles ESMAScript Edition 6 (ES6) code including classes, generators etc. to the regular JavaScript that current browsers support. You can clone the script from Github and start using locally in the Node.

You can download and read more about Traceur here at – traceur-compiler on githuub.

7. EMScripten

EMScripten is quite an interesting compiler! EMScripten compiles C and C++ into highly optimized JavaScript format, which is asm.js. Asm.js is subset of JavaScript based on ECMAScript and runs in the browser or anywhere else where JavaScript runs. The compiled JavaScript a.k.a asm.js runs in the browsers with almost native performance that C/C++ code could have achieved otherwise. OpenGL is converted to WebGL by EMScripten compiler.

EMScripten takes in LLMV bytecode and converts to JavaScript which essentially means that any code that can be converted to LLMV can be converted ultimately to high performant JavaScript. The biggest advantage is for C/C++ developers who can write directly for the web without even looking at what JavaScript is, another advantage is that we can convert thousands of existing C/C++native utilities to JavaScript and use in web browsers.

If we look at thousands of games that are made in C/C++, those can directly be compiled to JavaScript and run in web browsers.

More details about EMScripten here at official website – emscripten-site.

8. GWT

Google web toolkit offers one of the most powerful set of tools for developing performant front end applications using java language. There are still the hard core java lovers who love java to do anything from writing servers side code to database access to front end development. GWT is a perfect option for java lovers who do not want to get into browser quirks or do not want to deal with complexities of Ajax in raw JavaScript.

GWT is the creation of Google and Google uses GWT for many of its internal products including Google AdWords and Google Wallet. It’s open source under apache license, completely free, and has a fairly strong user community across the globe.

You can read more about GWT at –gwtproject.org.

9. LiveScript

LiveScript indirectly descends from CoffeScript via Coco of which it is a fork of. LiveScript is here since it compiles to JavaScript and offers many features to make functional style programming an absolute breeze. LiveScript is created by Jeremy Ashkenas who is the creator of CoffeScript, and is available under MIT license.

Satoshi Muramaki and George Zahariev are the other key developers who worked with Jeremy Ashkenas to create LiveScript.

You can read more about LiveScript at – livescript.net.

10. ClojureScript

ClojureScript is the love of many developers and is a very popular compiler of Clojure. Google Closure is set of tools that turn regular JavaScript into highly performant JavaScript. ClojureScript utilizes the same set of tools and is run past the same Closure compiler to emit compact, optimized JavaScript.

You can read more about ClojureScript here at – clojurescript.

Apart from the above mentioned JavaScript compilers – Dart, purescript and Opal are worth checking out.

Final Thoughts

The universe of JavaScript has expanded from client side web development to server side development to database engines to mobile apps development. The unprecedented growth must fulfill the demands of developers coming from different programming philosophies.

This demand cannot just be met with plain JavaScript itself. Many alternate programming and scripting languages that compile to JavaScript have evolved over the last few years to cater to the varied needs of development and would continue at least for next 5 years or so.

Do share your experience of working with languages and scripts that compile to JavaScript, via comments!!! Thanks.

Tags

noeticsunil

@noeticsunil

@noetic here, the founder of noeticforce.com. I love coding, quantum physics, and working on my brain to manipulate time.

More from Noeticforce
Join noeticforce

Create your free account to customize your reading & writing experience

Ⓒ 2021 noeticforce — All rights reserved