Moving from Coffeescript to ES6

Vladislav Kopylov
2 min readApr 30, 2017

--

After one year of using coffeescript, I started using ES6. Coffeescript is language that transcompiles to JavaScript. It has own syntactic sugar inspired by Ruby and Python.

ES6 is more powerful language standard than coffee. It has the same functional and some new features like constants, promises, proxying and others. Now all browser support es6 natively and you don’t need using a pre-processor like Babel.

Below, I wrote some examples of using es6-features and some alternative in coffeescript. I hope, this article will be useful for all developer that still use coffee and want to moving to ES6.

The same features

Function definition

ES6 has default values for function parameters like coffeescript. We can rewrite value of any variable if no value or undefined is passed. Also we can use spread for places any variables into a array.

coffee:

ES6:

String Interpolation

It is feature for inserting value of any variable into string.

coffee:

ES6:

Classes

ES6 has useful class definition more intuitive than ES5

coffee:

ES6:

New features

let and cost

Let and const are new variable types. Const is constants immutable variables, you can not change it value. Let is standard variable, but it is not hoisted.

Hoisted bug in coffee:

Hoisted bug in ES6 with using var:

Let and const in ES6:

Set()

Sets are new data structure. It similar to arrays (lists of values), but contain only unique values.

ES6:

coffee:

Map()

Maps are like objects. It contains key/value pairs. But it can store not only string for key.

ES6:

coffee:

That is all. If you are inspired by it and want to read more information, I recommend these addition links:

--

--

Vladislav Kopylov
Vladislav Kopylov

No responses yet