JS: ECMAScript 2015

By Xah Lee. Date: . Last updated: .

Over 10 major features are added to the language, effectively making JavaScript a new language.

Here is a quick overview of new features.

let

let is like var , but with a clean block-level scope.

const

const is similar to let, except you can't change its value once set.

Arrow Function

you can write function like this

((x, y) => { return x + y; });

but no this (binding) , and no arguments Object, no Function Name Hoisting .

Function Argument Default Values

function parameter can specify a default value.

Rest Parameters

function can now specify to take any number of parameters, by syntax ...args

Destructuring Assignment

// destructuring assignment
let [x, y, z] = [3, 4, 6];

Object Literal Expression, Computed Property Keys

new syntax for object literal to have computed property key by an expression.

obj = {[expression]:value}

Object Literal Expression, Method Definition Shorthand

new syntax shorthand for defining methods in object literal expression.

obj = { method_name() {body}, etc };

__proto__

Allow the use of property key __proto__ to get/set parent.

Template String

allows you to embed variable or expression in a string, or have newline char.

Spread Operator

The spread operator is 3 dots followed by a array, like this: ...myArray. What it does is effectively remove the bracket of the array.

for-of Loop

lets you properly loop thru an array, or new datatypes such as set and map, or any iterable object. Iterable object is a new concept, created just for for-of loops.

Interface, Iterable, Iterator, Generator

Iterable is new. It is a array like thing but items are generated at time it is used.

array is made iterable.

iterator is created to support iterable.

for-of loop and spread operator works with iterables.

these are created to support iterable.

Generator Function is created to support creating iterable.

Set Object

Set object lets you have a data structure of set. That is, a collection of unique values.

Map Object

Map object lets you have a data structure of key value pairs. Similar to JavaScript Object, but now designed to be used as a data structure. For example, keys can be any type, not just string.

Reflect

The Reflect object is used as namespace to host a group of static functions. Reflect methods typically duplicate operator behavior in function form, or provides a more strict or improved version of existing methods.

Class

class is a new keyword that lets you conveniently define object and its prototype.

New keywords are: class, constructor, static, extends, super.

regex

New regex flag "u". For unicode. Treat string as sequence of unicode characters.

New regex flag "y". For “sticky”. This means next regex match call will start with lastIndex.

New value properties.

New function properties.

New Array Properties

new array constructor properties

new array prototype properties

New String Properties

static methods

string methods

New Object Methods

New Function Properties

function property "name"

New Number Properties

new Math methods

html-like comments

formally recognize html comment.

block-level function declaration

now allow function declaration inside a block.

// es2015 block-level function declaration

function f() {
  function g(x) {
    return x + 1;
  }
  return g(1);
}

console.log(f()); // 2

Module, Keyword “import”, “export”

Unicode Escape Syntax

Now you can escape unicode by \u{4_to_6_hex_digits}

Octal and binary literals

// octal notation
console.log( 0o10 )
// 8

// binary
console.log( 0b10 )
// 2

new.target

xtodo

Promise

Subclassing

Misc

Annex b

ArrayBuffer

ECMAScript 2015 §Structured Data#sec-arraybuffer-objects

dataview object

Tail call optimisation (recursion)

WeakSet

WeakMap

JavaScript. ECMAScript New Features