es6.ruanyifeng.com/#docs/intro
1, let the command and const
- let
- let define variables, variables can not be redefined, but can change its value
- Having a block-level scope
- No variable lift, you must first define and then use
- Variables let statement is not pressed to the window object, independent
- const
- Use const keyword to define constants
- Constants are immutable, once defined, its value can not be modified
- When initialization constants must be given an initial value
- Having a block-level scope
- No variable lift, you must first define and then use
- Constant also independent, the definition is not pressed into window object
2, deconstruction assignment
- Deconstruction array assignment
let arr = [1, 2, 3];
let [a, b, c] = arr;
console.log(a, b, c); // 输出 1 2 3
复制代码
- Deconstruction object assignment
let { foo, bar } = {foo: 'aaa', bar: 'bbb'};
console.log(foo, bar); // aaa, bbb
let {a, c} = {a: 'hello', b: 'world'};
console.log(a, c); // hello, undefined
复制代码
- Deconstruction string assignment
- Deconstructing the assignment of function parameters
3, arrow function
// 非箭头函数
let fn = function (x) {
return x * 2;
}
// 箭头函数,等同于上面的函数
let fn = (x) => {
return x * 2;
}
复制代码
- Features arrow function
- Only one parameter, parentheses may be omitted
- You do not need to create a function key function
- Omit return keyword
- Function body braces can be omitted, and represents a function that returns the contents of the body
- No internal arguments
- Inside this outer scope of this point
- Not as a constructor
4、Promise
When the asynchronous request is increased, the area will become a callback, Promise asynchronous programming is a solution to solve the troubles of the developer asynchronous callback.
A Promise object has three states, and the state once changed, can no longer be changed to a different state.
- pending, asynchronous tasks in progress.
- resolved (also known as fulfilled), asynchronous tasks successfully.
- rejected, asynchronous task execution failed.
5, template string
Template string, string concatenation optimization, the ES5 by backslash 'do multiline string, for ES6 backticks' '' get directly.
// bad
const foo = 'this is a' + example;
// good
const foo = `this is a ${example}`;
复制代码
6, extended operator ?????
7, category (class)
Includes () function is used to determine whether the array contains a value of a specified return true if included, otherwise returns false.
8、for···of和for···in
for ··· of the array used to traverse
for ··· in is used to traverse the object
Reproduced in: https: //juejin.im/post/5d01a6315188251c064826a2