ECMAScript6 ES6 ES2015 new syntax summary

1. Let definition variables: can not be repeated definition, scope

2. const: define constant

3. Destructuring assignment: let [a, b, c] = [1,2,3]; // a = 1 b = 2 c = 3

4. Arrow function:

function fn (a, b) {
   return a + b;   
} 
// equivalent to 
let fn = (a, b) => {
   return a + b;   
} 
// and equivalent to (if there is only one return statement in the function Time) 
let fn = (a, b) => a + b;
 // If the function has only one parameter a 
let fn = a => a + b;

5. New method of array:

  map mapping:

let arr = [18,26,60,58,95,84];
let arr2 = arr.map(item => item>=60);/*[false, false, true, false, true, true]*/

 

Guess you like

Origin www.cnblogs.com/longfeiPHP/p/12716197.html