CoffeeScript: A Language That Compiles Into JavaScript

CoffeeScript is a little language created by Jeremy Ashkenas to speed up your JavaScript development. The golden rule of CoffeeScript is: “It’s just JavaScript”, as CoffeeScript compiles into JavaScript directly at compile-time. CoffeeScript offers its own syntax with a few simplifications compared to JavaScript, but it doesn’t want to substitute JavaScript; it just wants to decrease your development time. CoffeeScript also generates clean compiled JavaScript code and allows you to embed pure JavaScript and JavaScript libraries.

Try out CoffeeScript to check if you can enjoy its syntax. To have just a taste of what CoffeeScript looks like, let’s analyze a function that converts the temperature from Celsius to Fahrenheit, and let’s compare the JavaScript version with the correlated CoffeeScript version. This is the JavaScript version:

 var fahrenheit;
fahrenheit = function(c) {
return c * (9 / 5) + 32;

This is the CoffeeScript version:

fahrenheit = (c) -> c * (9/5) + 32

You will notice the simplifications in CoffeeScript. There are a few rules to learn, so there is a learning curve before getting up to speed with CoffeeScript, but you can end up decreasing your JavaScript code lines by using it.

Safari Books Online has the content you need

Take advantage of these CoffeeScript resources in Safari Books Online:

Programming in CoffeeScript covers everything experienced web developers need to evaluate CoffeeScript, “think” in CoffeeScript, and write high-performance software with it.
The Little Book on CoffeeScript shows JavaScript developers how to build superb web applications with CoffeeScript, the remarkable little language that’s gaining considerable interest.
Rails 3 in Action of course covers Rails 3, but in chapter 9, you learn how to test parts of your application that use JavaScript and about CoffeeScript, a neater language that compiles down to JavaScript.

About this author

Sebastiano Armeli-Battana is software engineer focused on JavaScript and Java development and he is really passionate about Web technologies. He works as consultant in SMS Management & Technology adopting Java technologies and he also works as Web freelancer. He is the author of a jQuery plugin called JAIL and he maintains his personal site at http://www.sebastianoarmelibattana.com.

About Safari Books Online

Safari Books Online is an online learning library that provides access to thousands of technical, engineering, business, and digital media books and training videos. Get the latest information on topics like Windows 8, Android Development, iOS Development, Cloud Computing, HTML5, and so much more – sometimes even before the book is published or on bookshelves. Learn something new today with a free subscription to Safari Books Online.

2 Responses to CoffeeScript: A Language That Compiles Into JavaScript

  1. Pingback: CoffeeScript: A Language That Compiles Into JavaScript « Safari … - EtondeGroup Blog of Web Applications | EtondeGroup Blog of Web Applications

  2. mjy says:

    Simplifying JavaScript is good. It’s also nice that your users don’t need to download JavaScript framework code. I wonder if it also makes JavaScript a little less error prone?