CoffeeScript – An Introduction

1 minute read

JavaScript developers (or any developer that uses JavaScript) know that the language can be, at times, awkward and clunky to use. While web developers try to promote agility and lightweight design through their code, languages like JavaScript (which inherits some of Java’s heavy syntax and design) at times seem self-contradictory. To handle JavaScript’s rigorous design while maintaining its powerful features, a new language was born: CoffeeScript.


If you have node.js installed into your computer, installing CoffeeScript (along with other JavaScript languages) is relatively straightforward.

**Screen Shot 2014-06-29 at 10.35.14 AM

** Type the above command into Terminal to install CoffeeScript. This uses the node package manager (npm) to install the CoffeeScript module globally.

Example of CoffeeScript Code

Let’s say you want to define a function in JavaScript (the function is called “something”). The code would look something like this:

Screen Shot 2014-06-29 at 10.30.52 AM

In CoffeeScript, you can accomplish this in one line of code.

Screen Shot 2014-06-29 at 10.33.51 AM

You would be able to reduce the amount of time spent coding in JavaScript drastically. Additionally, CoffeeScript is far more readable for non-JavaScript programmers. Although the drawback of learning another scripting language to handle JavaScript can be time consuming, CoffeeScript could still be potentially useful for expediting project development. You can check out CoffeeScript here.

How to Use .coffee Files

CoffeeScript is an intermediary for JavaScript. Scripts written in CoffeeScript are saved as .coffee files. The way it works is you first have to script a .coffee file and compile it into a .js file so you can actually use the program’s contents. To use CoffeeScript, all one has to do is cd to the directory containing a .coffee file. Let’s say you had a file called in this directory. Type the following command into Terminal to compile the .coffee file into a .js file.

Screen Shot 2014-06-29 at 10.35.40 AM

If you installed CoffeeScript globally using _npm, _then you should be able to run this command. That’s a basic overview of CoffeeScript!

Leave a Comment