ECMA6
//es6 1.变量声明 var 原因: 使用var声明变量存在作用范围混淆问题
// let :用来声明局部变量 好处: 作用范围严谨 从代码声明出开始 到代码块结束 一般在
声明基本变量使用推荐使用let
// const :用来声明js中常量 好处: 一旦被赋值不能被修改 推荐使用这两个关键字声明
变量 声明js中对象时推荐使用const 数组
//es6 2.在使用匿名函数时作为参数时候 function(){} 推荐使用es6中箭头函数
// (参数,参数)=>{函数体}
axios.get("url").then(function(res){}).catch(function(err){});
axios.get("url").then((res)=>{
}).catch((err)=>{});
//注意:
// 1.当箭头函数没有参数时或者参数大于1个 必须加入()
// 2.当箭头函数只有一个参数时 () 可以省略不写
// 3.当函数体中只有一行代码时 函数体{} 可以省略不写
// 4.箭头函数和匿名函数最大区别 箭头函数没有自己this 匿名函数存在自己的this
//es6 3. 模板字符串 使用语法: ` `
let html = "" +
"";
//es6 4. 对象定义 便利: 在定义对象时如果对象属性名和变量名一致,写一个即可
let id = 21;
let name = "小王";
let age = 23;
//es5.x版本
const emp = {id:id,name:name,age:age};
//es6.x版本
const emp1 = {id,name,age}
//es6 5. 模块导出和导入
// 导出
// math.js
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;
// 导入
// main.js
import { add, subtract } from './math.js';
console.log(add(2, 3)); // 5
console.log(subtract(5, 3)); // 2