9 programming languages that make coding JavaScript a joy

Need to program in JavaScript, but hung up on its limitations? Try a language that compiles to JavaScript instead.

9 worthwhile languages that compile to JavaScript
Credit: Iakov Kalinin
9 worthwhile languages that compile to JavaScript

JavaScript has become must-know tech, as widely spread through the IT ecosystem as Linux and virtualization. But the language bristles with syntactical traps, oddball design decisions, and limitations that can frustrate even the most seasoned developers.

Thankfully, a wealth of JavaScript mini-languages have arisen to take the pain out of programming in JavaScript, in many cases extending features otherwise unavailable to JavaScript itself. These languages, which compile down to JavaScript, may prove easier to code, maintain, and debug than JavaScript.

Following are seven JavaScript substitutes that make programming in JavaScript more productive and pleasant. Note that transpilers do exist for compiling existing languages to JavaScript -- e.g., Opal, which compiles Ruby to JavaScript -- but here we’re focusing on languages specifically written to compile to JavaScript.

CoffeeScript 1.7.1
CoffeeScript 1.7.1

Jeremy Ashkenas's CoffeeScript was one of the first attempts to simplify JavaScript’s syntax. It remains one of the most widely used JavaScript substitutes, borrowing ideas from a number of sources: From Python, the use of whitespace as syntax; from Ruby, which provided the original CoffeeScript compiler, the way variable scoping works. A special “literate” mode can be used for detailed annotation of the code. If you ever want to fall back to regular old JavaScript within CoffeeScript, you can do that by simply placing the JavaScript code inline and bracketing it with backticks.

The license is an MIT-style one, so CoffeeScript is wide open for re-use—leading to one major rewrite, CoffeeScriptRedux, and a slew of other spinoffs.

TypeScript 1.0.1
TypeScript 1.0.1

Created at Microsoft by Anders Hejlsberg (of C#, Delphi, and Turbo Pascal fame), TypeScript was designed to add features not normally available in JavaScript, such as classes, modules, interfaces, and an arrow syntax for anonymous functions. Arguably the most valuable of TypeScript’s features, though, is an optional static typing system, which allows TypeScript to be used effectively with language-analysis tools. Microsoft offers the whole project as open source under the Apache 2.0 license, as an add-on for Visual Studio, and as a Node.js package.

IcedCoffeeScript 1.7.0-a
IcedCoffeeScript 1.7.0-a

If CoffeeScript isn’t enough, consider IcedCoffeeScript. Dubbed ICS for short, it works as a one-for-one replacement for CoffeeScript, but it adds features to make it easier to handle asynchronous behaviors in CoffeeScript. For those who use these mechanisms often, ICS can be a major time-saver. (The screenshot here shows how terse IcedCoffeeScript code can be for such operations.)

The one disadvantage to using ICS is that the JavaScript produced by the compiler is a little more complex than CoffeeScript’s, making it a little less straightforward to the naked eye.

GorillaScript 0.9.7
GorillaScript 0.9.7

GorillaScript might be the most feature-packed language in this roundup. Among the functionalities it adds to JavaScript are optional typing, macros, generics, promises, iterators (found in ECMAScript 6 but available here), constants, and a slew of new operators that provide, among other things, type-checked operations and new logical functions. Not much has been done with the original Github repository of the project since last year, unfortunately, but it’s under a standard MIT license and so can be reused quite freely.

Kaffeine 0.1.6
Kaffeine 0.1.6

Billed as “extended JavaScript for pros,” Kaffeine extends JavaScript syntax in ways intended to make programming in the language a little less ornery. Unlike some of the other languages described here, Kaffeine lets you use JavaScript as-is and leaves you the option of using Kaffeine’s features at your discretion. For example, you can use the ! postfix operator to designate asynchronous operations -- something likely to appeal to any JavaScript programmer who’s been stuck in one of the circles of callback hell.

Dart 1.4.2
Dart 1.4.2

Dart is Google’s language aimed at replacing JavaScript, either by compiling to JavaScript or by running Dart natively in its own VM. So far, though, Dart hasn’t proved much of a threat to unseating JavaScript, but the language offers appealing features that are missing in JavaScript, such as optional typing, classes, and external libraries. It’s also easy to learn for those coming in from the JavaScript side of things, since Dart is similar enough to not throw off newcomers entirely.

Asm.js
Asm.js

Asm.js is an exception to the languages listed here in that it’s not a JavaScript dialect that one writes in directly. Rather, it’s a subset of JavaScript that’s produced from C/C++ code with special compiler tools. It works with most JavaScript engines but does get a performance boost from engines specifically tuned for asm.js.

Real-world tests of asm.js code show it runs at around half the speed of native code where supported, allowing things like sophisticated real-time gaming or number-crunching to happen right in the browser with no plug-ins. Right now, only the Firefox browser supports asm.js acceleration, but the core idea holds promise for those who want to use C/C++ as a source language and mix the results freely with JavaScript. 

Sweet.js
Sweet.js

Mozilla is proud of its Rust language, so much so that it created its own dialect of JavaScript with some of Rust's features. Sweet.js offers Rust’s macro functionality, allowing you to define your own syntax for anything from classes to custom operators. Some of the example macros include emulating the do notation found in CoffeeScript. It also includes convenience features, such as a module loader along the lines of the widely used Require.js.

LLJS
LLJS

Yet another Mozilla JavaScript research project, LLJS is closer to asm.js than any of the other projects on this list. LLJS adds to JavaScript a type system patterned after the one found in C, along with manual memory management using the same malloc and free instructions as C. “Think of it as inline assembly in C,” says Mozilla. That’s a hint at how this may not be something you want to use for production work, but might want to keep an eye on all the same to see how JavaScript evolves as both a low-level language and a high-level one.