CoffeeScript Tutorial

Introduction – CoffeeScript Tutorial

CoffeeScript is a light-weight, object-oriented, programming and scripting language. Codes that are written in CoffeeScript transcompile into javascript code. CoffeeScript provides easy syntax and flexibility while writing codes. This CoffeeScript tutorial has been designed for the absolute beginner who wants to learn the basic and advanced functionality of CoffeeScript.

CoffeeScript can communicate easily with Node.JS and ruby on rails applications. So CoffeeScript extends the reliability and the area of use.

Overview – What is CoffeeScript?

CoffeeScript actually works as a transcompiler of javascript codes. If you spend most of your time writing online and internet-based applications then you probably write lots of javascript codes. In this case, you can write CoffeeScript codes instead of writing javascript codes for the same task.

If you do that so you can reduce hundreds of thousand lines of code and also reduce complexity and avoiding the critical parts of javascript. So having knowledge of CoffeeScript can be useful if you are mostly working on web applications.

Origin of CoffeeScript

CoffeeScript first appeared in 2009 designed and developed by Jeremy Ashkenas. CoffeeScript was inspired by many high-level programming languages like, Python, Ruby, Haskell, Perl, YMAL, etc that’s why it provides very high-level syntax that made CoffeScript very easy to learn and understandable. See below why you should learn CoffeeScript.

Why you should learn CoffeeScript

CoffeeScript uses nearly the same style of Python programming. Using very high-level syntax you can easily write complicated javascript solutions. There are more:

  • Human readable: As CoffeeScript is inspired by many high-level languages, it is super easy to read and maintainable codes.
  • Reliable: CoffeeScript can easily communicate with Python, Ruby, and nodeJS apps. So CoffeeScript is very extendable for writing powerful web apps.
  • Less code do more: Using the high-level syntax, you can write powerful and complex problems with less code than writing in typical Javascript.
  • Extended library support: You can do more stuff by including and writing rich library functions.

A simple CoffeeScript Program

In the below CoffeeScript program, we have printed out the natural numbers 1..10 using the loop. You don’t need to figure out what is happing right now, but keep in mind that you can write many complex programs by using the near plain language syntax.

count = 0
while count < 10
   console.log "Index : " + count
   count++;

If you transcompile and run the following code you will get

Output:
> Index: 1
> Index: 2
> Index: 3
> Index: 4
> Index: 5
> Index: 6

In the next subsequent tutorials, we will learn CoffeeScript from most basic concept to advanced programming concept. Let’s start!