核心提示:ES6箭头函数和扩展代码实例讲解// 主动抛出异常function add(a,b = 1){if(a == 0){throw new Error(A is Error);}return a+b;}c...
ES6箭头函数和扩展代码实例讲解
// 主动抛出异常 function add(a,b = 1){ if(a == 0){ throw new Error('A is Error'); } return a+b; } console.log(add(0));
function add(a,b = 1){ if(a == 0){ throw new Error('A is Error'); } return a+b; } // 获取函数参数个数 console.log(add.length); // 返回1,返回必须传递的参数个数,此处是a
箭头函数
var add = (a,b = 1) => a + b; document.write(add(1)); var add = (a,b = 2) => { document.write('js') return a + b; } document.write(add(2));