1. 在用||做条件判断时,如果情况较多,我们可以考虑是否能够用Array.includes()方法代替
var conditionArray = [ test1, test2, test3 ]; if ( conditionArray.includes(value) ) { // do something.. }
2. 默认参数和参数的解构
function say({ name } = {}) { console.log(name || 'unknown'); }
1. 在用||做条件判断时,如果情况较多,我们可以考虑是否能够用Array.includes()方法代替
var conditionArray = [ test1, test2, test3 ]; if ( conditionArray.includes(value) ) { // do something.. }
2. 默认参数和参数的解构
function say({ name } = {}) { console.log(name || 'unknown'); }