A demonstration of some ECMAScript 6 features.

Also known as ES6 and ES2015.

Below are interactive examples of various ES6 features. Code in the first box is interpreted and the results are displayed in the second box. Only the final value is displayed in the 2nd box. If you want to show more than 1 value, concatenate multiple values into a single string.

Const

const declares a constant value which cannot be changed.

Let

let lets you declare block level variables while variables declared with var are visible throughout the function.


Arrow Functions

Functions can be implicitly declared via an arrow- => .

Default Parameters

Parameters for functions can have default values.

Named Parameters

Simulate named parameters via destructuring.

You can use defaults as well.

Spread Operator

The spread operator (...) allows you to pass an arbitrary number of values to a function which are concatenated to a single array.




The spread operator can also split a string or array into individual elements.

String Repeating
String Interpolation

By using backticks, you can mix strings, variables and code.

Method Shorthand

Object methods can be declared implicitly.

Exponentiation

Use the ** operator to perform exponentiation.

Object.values

Use Object.values to get an array of the values in an object.

Object.entries

Use Object.entries to get an array of the entries in an object. This way you can loop through all of the entries in an object like an array.

Other Resources