CoffeeScript | Introduction
In this tutorial, the readers will learn the basic functionality of CoffeeScript with code to build dynamic websites and web applications after mastering it.
History: The CoffeeScript language is designed by Jeremy Ashkenas. It was first introduced on 13 December 2009 on the git when Jeremy Ashkenas made the first git commit of CoffeeScript. On February 21, 2010, the first pure CoffeeScript compiler was released earlier the CoffeeScript compiler was in Ruby language. By that time the GitHub project attracted many contributors to GitHub making it the most demanded project of that time.
# Install locally for a project: npm install --save-dev coffeescript # Install globally to execute .coffee files anywhere: npm install --global coffeescript
Advantages of CoffeeScript:
- No symbols: The symbols like semicolons, parenthesis, and curly braces do not play any role in CoffeeScript. Instead of these, whitespaces are used to differentiate the code inside functions, loops, etc.
- Maintainable: CoffeeScript provides the concept of aliases for many operators which makes code understandable easily, readable. It becomes easy to maintain programs written in CoffeeScript.
- Reliable: CoffeeScript is a reliable and safe programming language to make dynamic web pages.
To execute a CoffeeScript file, you need to type the following command:
coffee -c filename.coffee
The syntax is not quirky. For example, if you want to print something on the console then you just need to type it inside console.log without parenthesis as shown below.
- Significant whitespace
- Straight forward class definitions and functions
- Lambda functions
Limitations: The only limitation of CoffeeScript is that it is very sensitive to whitespaces. If the proper indentation is not maintained, the error will be thrown. So, programmers need to be very careful with whitespaces.
CoffeScript vs Typescript:
|It is best used when we want more readable code and lots of syntactic sugar.||It is best used when we want optional static typing and better tool support.|
|It is used for server-side web applications only.||It is used for both server-side and client-side web applications.|
|It is developed and maintained by the Open Source developer community itself under the MIT License.||It is developed and maintained by Microsoft under the Apache2 License.|
Is CoffeeScript dead?