js传参默认值

127 阅读1分钟

js传参时,默认值的设置

  • 不传参数时,默认取值
  • 传参数时,取传递值
  • 如果多个参数,某个参数需要使用默认值时,则需要传 undefined
  • function test2(a=1,b=2){ console.log(`a=a,b={a},b={b}`) }
  • test2()
  • test2(undefined,100)
  • test2(200,300)

a = 1,b=2

a= 1, b= 100

a = 200, b= 300