在ES6里面我们可以去给函数接受的参数制定默认的值,那么在执行这个函数的时候,如果不指定函数的参数的值的话,就会使用这些参数默认的值

 

例子:
function breakfast(dessert = 'cake',drink = 'tea'){
return `${dessert} ${drink} `
}
console.log(breakfast()); //cake tea
 
这里没有给函数设定参数,所以使用了默认的值;如果设定了参数,则会使用设定的参数值。

 

例子:
function breakfast(dessert = 'cake',drink = 'tea'){
return `${dessert} ${drink} `
}
console.log(breakfast('馒头','啤酒'));   //馒头 啤酒
 

相关文章:

  • 2021-10-18
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2021-08-17
  • 2022-12-23
猜你喜欢
  • 2021-07-31
  • 2021-06-18
  • 2021-11-13
  • 2021-05-01
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案