coffeescript it is javascript

Hello Guys I learned a new language and I am going to share and tell you how it works.

What is CoffeeScipt?

CoffeeScript is a little language that compiles into JavaScript. It is an attempt to expose the good parts of JavaScript in a simple way yet retaining the flexibility and beauty of the language. The golden rule of CoffeeScript is: “It’s just JavaScript”.

How to Install CoffeeScript?

You require node. js in your system which you can download from

Then install npm, that you can download from here

Run this command

$ npm install -g coffee-script

You can also install it globally by using this command line

npm install --global coffeescript

and locally in a folder using this

npm install --save coffeescript


  • No variable declaration required
  • Least amount of code to solve problems
  • Readable and Understandable
  • Easy to Maintain
  • No semicolons or parenthesis required
  • Reliable
  • Class-based inheritance
  • Extensive library support

How it Works?

We use indent to give our code a better visual appearance. But CoffeeScript takes this convention and makes it part of the language to tidy up all those curly braces. You might have seen indent in the above coffeescript code.

Indentation adds to the readability of CoffeeScript and it removes lots of the unnecessary braces.

In CoffeeScript, the arrow -> is used to define a function, with the parameters in brackets in front. If a function has no parameters, the brackets are optional. You will see it below in example.

Classes in CoffeeScript

Most of the programming language like java, php C# has class keyword to define class. JavaScript is a language limited by few rules and its ability to define OOP classes in many ways is powerful, yet confusing to many. CoffeeScript solves this by adding the class keyword

CoffeeScript Classes Example

class Cars
  constructor: (@carname) ->

hello: ->
    console.log "New #{@carname}"

Now JavaScript Compilation of above CoffeScript

var Cars;

Cars= (function() {
  function Cars(carname) {
    this.carname= carname;

Cars.prototype.hello = function() {
    return console.log("New" + this.carname);

return Cars;


Here some code below in CoffeeScript

Just alert in coffeescript
alert "Hello CoffeeScript!"

Message in Variable
message = "First code"
alert message

Function in coffeescript
coffee = ->
	newm = "Hello"
	"Message printed is " + newm
alert coffee()
Sum of two numbers
sum = (a,b)->

Here is the JavaScript version of above CoffeeScript

var coffee, message;
Just alert
alert("Hello CoffeeScript!");

Message is Variable
message = "First code";

coffee = function() {
  var newm;
  newm = "Hello";
  return "Message printed is " + newm;
Sum of two numbers
sum = function(a, b) {
  a = 2;
  b = 5;
  return a + b;

Try Above code here.

List of command for command line

  -b, --bare         compile without a top-level function wrapper
  -c, --compile      compile to JavaScript and save as .js files
  -e, --eval         pass a string from the command line as input
  -h, --help         display this help message
  -i, --interactive  run an interactive CoffeeScript REPL
  -j, --join         concatenate the source CoffeeScript before compiling
  -m, --map          generate source map and save as files
  -M, --inline-map   generate source map and include it directly in output
  -n, --nodes        print out the parse tree that the parser produces
      --nodejs       pass options directly to the "node" binary
      --no-header    suppress the "Generated by" header
  -o, --output       set the output directory for compiled JavaScript
  -p, --print        print out the compiled JavaScript
  -r, --require      require the given module before eval or REPL
  -s, --stdio        listen for and compile scripts over stdio
  -l, --literate     treat stdio as literate style coffee-script
  -t, --tokens       print out the tokens that the lexer/rewriter produce
  -v, --version      display the version number
  -w, --watch        watch scripts for changes and rerun commands

By now you might have realised that writing code in Coffeescript is much easier than a regular JavaScript. I have not given complete details about CoffeeScript, i will write another post on that, but for now head to the official site and learn CoffeeScript.

You can learn CoffeeScript for free for first level here.

Previous articleAwesome Limited Edition Cars
Next articleWhat is .htaccess and how can you remove extension from url using htaccess
Hello Guys I am a freelance website developer and digital marketer, I have over 4 years of experience. I create websites using PHP, Wordpress, angular js, HTML, CSS, Jquery, Javascript. I also create an eCommerce website, using Magento, open cart, woo-commerce, Shopify, big commerce. The platform is selected according to client needs. I will also help you create your native mobile app which will work on both android and IOS which is created using PWA for your new website or existing website. I also have a digital marketing team, which fulfills all your needs related to creating or enhancing digital presence.



This site uses Akismet to reduce spam. Learn how your comment data is processed.