What is CoffeeScript?
What it is
CoffeeScript is a small language that compiles to JavaScript. You write .coffee files, run the compiler, and get plain .js files back.
Jeremy Ashkenas built it in 2009 because JavaScript at the time was painful to write. No arrow functions, no string interpolation, no destructuring, no classes. CoffeeScript gave you all of that years before ES6 existed. A lot of what you write in modern JavaScript today traces directly back to ideas CoffeeScript popularised first.
.js files are included so you can run everything without installing CoffeeScript first.
Quick syntax reference
| Feature | JavaScript | CoffeeScript |
|---|
Files in this repo
Running it
Should you use it for a new project?
Probably not. ES6+ covers most of what CoffeeScript offered, and TypeScript is the better pick if you want a compile-to-JS language with real tooling support.
That said, it is worth knowing:
- A lot of older codebases still use it, especially Rails apps
- ES6 syntax owes a lot to CoffeeScript
- It compiles to readable JavaScript, so picking it up is low risk
- The source for this repo is CoffeeScript, so you can see exactly how it works
References
Ashkenas, J. CoffeeScript: Accelerated JavaScript Development. Pragmatic Bookshelf, 2011.
CoffeeScript Language Reference: coffeescript.org
ECMA International. ECMAScript 2015 Language Specification. ECMA-262, 6th Edition, 2015.