const 变量
多使用 const ,有利于提高程序的执行效率,let 和 const 编译器的内部处理不同
字符串
使用单引号,和反引号,
解构赋值
const arr = [1, 2, 3, 4];
const [first, second] = arr;
如果函数的参数是对象成员,优先使用解构赋值,
// good
function getFullName(obj) {
const { firstName, lastName } = obj;
}
// best
function getFullName({ firstName, lastName }) {}
- 对象
===
预防错误编程
props
eslint
===
使用 rest 运算符
使用默认值语法,设置参数的默认值
function handleThings(opts = {}) {}