JavaScript ES6 Features
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Introduction
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Source: ES6 Features
Scoping
for(let item of document.querySelectorAll('.item')) {
item.onclick = function() {
console.log('Index: ' + item.dataset.index);
}
}
Constants
const id = 'cache.custom';
Extended Parameter Handling
Default Parameter Values
function f(x = 5, b = true) { ... }
Rest Parameter
function f(x, y, ...a) { ... }
Spread Parameter
const a = [1, 2, ...params];
f(...a);
Template Literals
String Interpolation
const s = `Hello ${user.name}!`;
Custom Interpolation
foo`Hello ${user.name}!`;
function foo(strings, ...props) {
// Handle interpolation
}
Enhanced Object Properties
Property Shorthand
const x = 5, y = 0;
const p = { x, y };
Destructuring Assignment
Array Matching
const [a, , c] = [1, 2, 3];
Object Matching & Deep Matching
const { x, y } = { x: 5, y: 0, b: false };
const { event: { type }, b: valid } = { event: { type: 'click' }, b: true };
Parameter Context Matching
function f({ name, email }) { ... }