This document introduces ES2015 (ECMAScript 2015), which updated the JavaScript language with new syntaxes and libraries. It summarizes some of the key additions, including classes, template literals, object literal extensions, Maps, destructuring, and more. These features are now supported by modern browsers. The document provides examples of code using the old syntax versus the new syntax for classes, template literals, Maps, and destructuring to illustrate the changes. It also lists some references for further exploring ES2015.
14. After Map
var map = new Map([
['name', 'david'],
[true, 'false'],
[1, 'one'],
[{}, 'object'],
[function () {}, 'function']
]);
map.has('name');
map.set('name', 'john');
map.get('name'); // john
15. Before destructuring
var arr = [1, 2, 3, 4];
var a = arr[0];
var b = arr[1];
var c = arr[2];
var d = arr[3];
var luke = { occupation: 'jedi', father: 'anakin' };
var occupation = luke.occupation; // 'jedi'
var father = luke.father; // 'anakin'
16. After destructuring
var [a, b, c, d] = [1, 2, 3, 4];
var luke = { occupation: 'jedi', father: 'anakin' };
var {occupation, father} = luke;
17. And More
• spread (...) operator
arr1.push(...arr2)
• for of loop
• Promise
• Symbol
• Object.assign
18. Reference
• Exploring ES6: Upgrade to the next
version of JavaScript
• DrkSephy/es6-cheatsheet: ES2015
[ES6] cheatsheet containing tips,
tricks, best practices and code
snippets
• lukehoban/es6features: Overview of
ECMAScript 6 features