1.7 KiB
1.7 KiB
Features
Array comprehension
[for (i of [1, 2, 3]) i * i]; // [1, 4, 9]
Arrow functions
arr.map(x => x * x);
Block binding
for (let i in arr) {
let v = arr[i];
}
Classes
class Foo extends Bar {
constructor() { }
foo() { }
get bar() { }
set bar() { }
}
Computed property names
var obj = {
["x" + foo]: "heh",
["y" + bar]: "noo",
foo: "foo",
bar: "bar"
};
Constants
const MULTIPLIER = 5;
console.log(2 * MULTIPLIER);
MULTIPLIER = 6; // error
var MULTIPLIER; // error
Default parameters
function foo(bar = "foo") {
return bar + "bar";
}
Destructuring
var [a, [b], c, d] = ["hello", [", ", "junk"], ["world"]];
console.log(a + b + c); // hello, world
For-of
for (var i of [1, 2, 3]) {
console.log(i * i);
}
Generators
Modules
Numeric literals
0b111110111 === 503; // true
0o767 === 503; // true
Property method assignment
var obj = {
bar: "foobar",
foo() {
return "foobar";
},
get bar() {
},
set bar() {
}
};
Property name shorthand
function f(x, y) {
return { x, y };
}
Rest parameters
function printList(name, ...items) {
console.log("list %s has the following items", name);
items.forEach(function (item) {
console.log(item);
});
};
Spread
function add(x, y) {
return x + y;
}
var numbers = [5, 10];
add(...numbers); // 15
Template literals
var x = 5;
var y = 10;
console.log(`${x} + ${y} = ${x + y}`); // "5 + 10 = 15"