ES6/ECMAScript2015 Cheatsheet

Installation

Babel:

  • CLI: $ npm install -g babel-cli

  • Require: $ npm install -g babel-core

  • Browser: <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>

  • Gulp: $ npm install --save-dev gulp-babel

Usage

  • CLI: $ babel script.js or $ babel script.js

  • Require: require("babel-core/register");

  • Browser: <script type="text/babel"></script>

Gulp:

var gulp = require('gulp'),
  babel = require('gulp-babel')

gulp.task('build', function () {
  return gulp.src('src/app.js')
    .pipe(babel())
    .pipe(gulp.dest('build'))
})

Default Parameters in ES6

Template Literals in ES6

Multi-line Strings in ES6

Destructuring Assignment in ES6

Enhanced Object Literals in ES6

Arrow Functions in ES6

Promises in ES6

Block-Scoped Constructs Let and Const

Classes in ES6

The output is:

Modules in ES6

module.js file:

main.js file:

Or import everything as a variable service in main.js:

More ES6 Features

  1. New Math, Number, String, Array and Object methods

  2. Binary and octal number types

  3. Default rest spread

  4. For of comprehensions (hello again mighty CoffeeScript!)

  5. Symbols

  6. Tail calls

  7. Generators

  8. New data structures like Map and Set

Resources

Last updated

Was this helpful?