### 變量聲明
```js
var a , b; // 確定:變量提前
```
##### ES6寫法:
```js
// 不可以在定義前使用,塊級作用域
console.log(a)
if (true) {
let a = 1 , b = 0;
}
// 定義常量
const PI = 3.14
```
###
### 模板字符串
```js
var str = 'world';
var result = 'hello' + str;
```
##### ES5寫法:
```js
// 使用反引號
var str = 'world';
var result = `hello ${str}`;
```
###
### 模塊 \(ES5原生不支持\)
##### ES6中:
\(1\) 按需導入
```js
// 文件 config.js, 導出模塊
const A = {
name: 'zk'
};
const B = {
name: 'wl'
};
export A
export B
```
```js
// main.js 用到,導入模塊
import {A} from './config.js'
import {B} from './config.js'
import {A,B} from './config.js'
import * as type from './config.js'
console.log(type.A.name)
```
(1)按需導入
```js
// 文件 config.js, 導出模塊
const A = {
name: 'zk'
};
const B = {
name: 'wl'
};
export A
export default B
```
```js
// main.js 用到,導入模塊
import {A} from './config.js'
import {B} from './config.js'
import {A,B} from './config.js'
```
### 箭頭函數
```js
let that =this;
setTimeout(function () {
alert(this) // window || undefined
}, 1000)
setTimeout(() => {
console.log(this) // this = that
})
```
### 對象的擴展
```js
let name = 'zk'
let obj = {
name,
say () {
console.log('hello')
}
}
obj.name;
obj.say();
```
### ... 擴展運算符
```js
let arrs = [1, 3, 4, 7, 5, 3]
Math.max(...arrs)
```
### Object.assgin方法
Object.assign() 方法用于把一個或多個源對象的**可枚舉屬性值**復制到目標對象中,返回值為目標對象。
```js
var obj = {a: 1};
var copy = Object.assign({}, obj);
console.log(copy); // {a: 1};
```
常見用途:
1. 合并多個對象
2. 克隆對象(淺復制)
3. 為對象添加多個方法