• Cosimo Orban

ES6 features to start with

Arrows =>

Arrows are a shorthand for function.

Old way:

users.forEach(function(user) {
    // do something with the user

New way:

users.forEach(user => {
    // do something with the user

Important tip: Arrow functions share this as the code surrounding them, unlike functions.


Classes are just sugar around OO prototype system.

Old way:

var Person = function (name) {
    this.name = name;
Person.prototype.getName = function () {
    return this.name;
var john = new Person('John Smith');
console.log(‘My name is‘, john.getName());

New way:

class Person {
    constructor(name) {
        this.name = name
    getName() {
        return this.name
var john = new Person('John Smith')
console.log(‘My name is, john.getName())

Template Strings

Old way:

var textConcatenation = 'Timestamp: ' + Date.now();

New way:

var templateStrings = `Timestamp: ${Date.now()}`



export const error = (message) => { console.error(message) }
export const warning = (message) => { console.warning(message) }


export * as Log from 'log'

# The message will be logged as error. This is a bad error message. More on error messages here: http://layer0.authentise.com/your-error-messages-are-bad-and-you-should-feel-bad.html
Log.warning('The system is overheating')
Log.error('Segmentation fault')


Functions can now have arguments with default value

function sum(x, y=10) {
    return x+y

sum(1) // 11

Rest + Spread

Skip passing arguments one by one

function sum(...numbers) {
    return numbers.reduce((a, b) => a + b, 0)
var numbers = [1, 2, 3, 4]
sum(numbers) // 10

Once you've added the above new features into your code, you could continue to explore the many more features that 6th edition has to offer: http://www.ecma-international.org/ecma-262/6.0/index.html

7 views0 comments

Recent Posts

See All

Tips on API and Database Creation

Intro Lately I've been working on creating an API that interacts with a database and I picked up on some mistakes that I made and thought it would help everyone out to share it. I'll be starting off w