Quick Guide to Coffeescript

Seann Branchfield
Oct 3, 2019 · 2 min read

There are a number of good references on the internet on Coffeescript. The intent of this article is to basically toss out the absolute basics for people who are unfamiliar who need to quickly look over a codebase and have some clue what is going on!

In case you don’t already know it, Coffeescript compiles to Javascript. It’s just an alternative syntax which makes it look a lot more like Python/Ruby.

Variables

Variables are not declared with var, let or const. They are set just how they would be in Python or Ruby:

name = “Sam”

num = 5

The major downside of this is that you can never treat variables as if they were let or const.

Also, like Ruby, instance variables start with a @.

Functions

Functions are declared with a thin arrow ->, although fat arrows (=>) just like in ES6 are also available! There are no curly braces and no “function()”, so the white space and indentation is mandatory.

Notice the difference between a public and private function

Objects

Objects no longer have parentheses or commas. White space is very critical!

Aliases

Also important to note…there are some aliases that coffeescript has that you might see in code:

|| in Javascript is equivalent to or

! is equivalent to not

this is is equivalent to @

This is not a full listing but if you feel like you are seeing something that looks like it has an alternate name, you can search!

More on Coffeescript

There is excellent documentation on Coffeescript online just a search away. I highly recommend digging in further if you have time if it is something you need to use.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade