ES6中函数参数默认值问题

2023-04-27,,

参数默认值

   	// 以前的参数默认值写法
let fn = (a, b) => {
a = typeof a === "undefined" ? 10 : a
b = typeof b === "undefined" ? 5 : b
console.log(a, b);
}
fn(undefined, undefined)//10,5 //ES6的写法
let fn1 = (a=10, b=5) => {
console.log(a, b);
}
fn1(undefined, undefined)//10,5
fn1(1,2)//1,2 函数默认值不影响函数参数的正常使用
    fn1(1,2)//1,2  函数默认值不影响函数参数的正常使用

ES6中函数参数默认值问题的相关教程结束。

《ES6中函数参数默认值问题.doc》

下载本文的Word格式文档,以方便收藏与打印。