JavaScript vs CoffeeScript vs TypeScript

  • Home
  • /
  • Blog
  • /
  • JavaScript vs CoffeeScript vs TypeScript

JavaScript

 JavaScript is  a dynamic, advanced level interpreted programming language. It is one of the three core technologies of World Wide Web alongside HTML and CSS. The majority of websites employ it and it is supported by all modern Web browsers. JavaScript is prototype-based with first-class functions, making it a multi-purpose tool, supporting functional and object-oriented programming styles. It includes an API for working with arrays, expressions and texts, but does not have any I/O support, like storage, media, networking and graphics facilities. For these it has to rely on the host environment but there are frameworks like Node.js to leverage all advantage of javascript.

JavaScript is also used in applications that are not entirely web-based, like desktop widgets, website-specific browsers and PDF documents. It also plays an important part in game development, desktop/mobile applications, and server-side network programming.

JavaScript development has got even better with the advent of various new frameworks. For server-side web development one can use a multitude of languages and frameworks, but for client-side programming JavaScript is the sole option as it is supported by all browsers. To overcome this problem, newer languages were developed that can compile down to JavaScript. These new languages offer new concepts and improved syntax while hiding the complex bits of the JavaScript. They can offer good ways to write and manage large code, while automatically generating more ‘correct’ JavaScript as an alternative.

Why Javascript is so popular on server-side too? Because, thanks to Google, it can be run by ultra fast ES6 compiler that provides high speed comparing to other interpreted languages like Ruby, Python.

Coffeescript 

Coffescript is one of these languages, and a popular one. Its syntax is kind of similar to JavaScript, but has a lot of changes for the sake of cleaner, more concise code. It’s comparatively easy to read, and becomes more easy to learn after some good effort.

Coffeescript is a clean little language type that nicely compiles into the JavaScript. Underneath those lame complex ‘braces and semicolons’ composed structure, JavaScript has always had a classic object model at its heart. Coffeescript is an attempt to expose the good and bad parts of the JavaScript in a simple easier way.

The classic rule of Coffeescript is: ‘It’s just a plain JavaScript’. The Coffeescript code compiles one by one into the equivalent JavaScript, and there is no interpretation at the runtime. The final compiled output is readable and nicely printed, passes through JavaScript without warnings, will work in every other JavaScript application or usage, and aims to run as fast or much faster than the plain equivalent handwritten JavaScript.

Aside from syntax, there are also some other features and improvisations in the Coffeescript. Like variable scoping is improved, there’s no need to actually declare variables, just use desired variables and they are declared for you in the output. 

Typescript

Typescript is a newer contender, developed by Microsoft and made to have first class citizen support in Visual Studio including Intelligence and on-the-fly compiler errors. TypeScript differs from Coffeescript in a way that it’s just a complete superset of JavaScript. All JavaScript code is totally valid TypeScript code.

TypeScript provides lot of help for generating better JavaScript, such as a natural syntax for defining classes. TypeScript has one major benefit which is the optional support for static type checking, which makes it a lot easier to interface with the external JavaScript libraries either without type checking or with a typed interface definition that you create.

TypeScript integrates well with all the existing JavaScript code and it’s easy to understand even if u know a little bit of JavaScript and C. Another point why to choose TypeScript is that someday today’s TypeScript will be standard JavaScript and therefore run in the browser.

TypeScript allows you to create today’s web applications with language features of tomorrow. TypeScript is the only one that is a very strict superset of JavaScript.  This means that any type of valid JavaScript code is also good for TypeScript, and surely compatible with existing libraries without any problem.

This nice compatibility, however, has some issues as well.  As a superset, TypeScript cannot make up for any of the JavaScript’s ugly complex sides.  So, all the pitfalls of the JavaScript are there lurking, waiting for you to make a mistake. In the TypeScript the static typing and Visual Studio plugins do a lot to alleviate these problems, though.

TypeScript usually supports all the definition files that contain method information of existing JavaScript libraries, much like C/C++ header files that explain the structures of previous object files. This enables other programs to use all the values defined in the files as if they were TypeScript entities which are statically typed.

TypeScript is obviously a forward step at what JavaScript may be in a few years’ time.  The addition of, classes, modules, a type system and an IDE that takes full use of these features makes it a very tempting choice over plain JavaScript.

Overall, TypeScript is relatively much closer to JavaScript than Coffeescript, making it easier to learn as well as the generated output is closer to the input in its case.

Coffeescript or Typescript?

There’s a good case for both of them, and if someone didn’t mind the odd maintenance and mental torture, he could actually use both of them on the same project. Since both compile to JavaScript, one can easily use any code written in the other language.

Following are some recommendations:

  1. For static type checking and a good tool chain support on Visual Studio, TypeScript is the option.
  2. For a quick and short learning curve from JavaScript or a need to add legacy code (which isn’t common since it can easily be used as old JavaScript without modification), choose TypeScript.
  3. If someone wants more concise, cleaner code and lots of syntactic sugar, choose Coffeescript.
  4. If coming from Ruby or Python, Coffeescript is likely to be a good option, as it’s a closer mental match.

Summary

Coffeescript:

  • Small, clear language with lots of code examples.
  • Effective after learning the basics.
  • Good working tools provided.

TypeScript:

  • Developed by Microsoft (yes, some of developers may consider this as disadvantage)
  • Each part of JavaScript code is valid TypeScript and therefore it integrates much better than the other languages.
  • Compatible with next-gen JavaScript standards.
  • Compiled JavaScript runs on server (node.js).
  • Similar syntax as in C/C++.

prev
next