01-let.js
// variable var is not declared local scope // variable declaration is let local scope { var A =. 1 ; let B =. 1 } the console.log (A) the console.log (B) // var may declare multiple // the let only once can be declared var m. 1 = var m = 2 the let n- =. 1 the let n- = 2 the console.log (m) the console.log (n-) // var variable lift will // the let absent variable lift the console.log (X) var X = 'Apple'
02-const.js
// a value of a constant, constant change can not be declared const const PI = 3.1415 PI = 3 // constant but a declaration must be initialized, otherwise it will error const UI
03- deconstruction assignment .js
// 1. Array deconstruction // Traditional the let A =. 1 the let B = 2 the let C =. 3 the console.log (A, B, C) // ES6 the let [X, Y, Z] = [l, 2,3 ] the console.log (X, Y, Z) // 2, the object deconstructing the let = {User name: 'Hello', Age: 18 is } // traditional the let NAME1 = the user.name the let AGE1 = user.age the console.log (NAME1 , AGE1) // ES6 // Note that variables must be deconstructed and user attributes with the same name in the let {name, Age} = user the console.log (name, Age)
04- template string .js
// template string is equivalent to the enhanced version of the string with backquotes `, except as ordinary strings can also be used to define multi-line strings, you can also add variables and expressions in the string. // string into variables and expressions. Variable names written in the $ {}, {} $ JavaScript expression can be placed in the let name = 'GYY' the let S = `Hao are you $ {name}` the console.log (S)
05- declare an object abbreviated .js
name = const 'Perter' const Age =. 19 // conventional const Person = { name: name, Age: Age } the console.log (Person) // ES6 // Person in the name, age and must be defined attribute name, age same attribute can be abbreviated const PERSON2 = { name, age } the console.log (PERSON2)
06- shorthand method defined .js
// conventional const persons = { name: 'GYY' , Age: 18 is , the sayHi: function () { the console.log ( 'Hi' ) } } persons.sayHi () // ES6 // methods may be directly dispensed shorthand ' : function 'in parentheses to the general method of default const peropet = { name: ' Dandan ' , Age: . 19 , the sayHi () { the console.log ( ' haha ' ) } } peropet.sayHi ()
07- expand the object operator .js
Person = the let { name: 'Hi' , Age: 20 is } // reference assignment change the value of the original object. Java memory reference and similar to // the let someone Person = // expand operator (...) for removing all the parameter object attributes can then traverse copy of the current object does not affect the value of the property of the original object the let someone = { Person} ... someone.name = 'Hello' the console.log (PERSON.NAME)
The default function parameters .js 08-
function Showtime (name, Age = 18 is ) { // to set the default parameters of the function, if there is no default parameter values are used pass the console.log (name + ',' + Age) } // Showtime ( 'NiHao', 20 is) showtime ( 'nihaoya')
09- Arrow function .js
// the comparison is the first letter of the array size sorting the let ARR = [20,5,10000,80,30 ] the let of arr1 = arr.sort () the console.log (of arr1) // by size values to compare let arr2 = [20,5,10000,80,30 ] the let ARR3 = arr2.sort ( function (A, B) { return A- B }) the console.log (ARR3) // arrow function let arr4 = [20,5, 10000,80,30 ] the let arr5 = arr4.sort ((A, B) => { return A- B }) the console.log (arr5) // if the process can be simplified into only one sentence removed return the let arr6 = [ 20,5,10000,80,30 ] the let arr7arr6.sort = ((A, B) => BA) // if the brackets can be simplified into only one parameter = A> BA the console.log (arr7)