码迷,mamicode.com
首页 > 其他好文 > 详细

重学ES6(三):函数和箭头函数

时间:2020-02-06 23:30:44      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:箭头   console   设置   pre   参数   箭头函数   默认值   undefined   turn   

函数的参数默认值

ES5---参数的默认值通常都是写在函数体中,不传参即用默认参数

// ES5
// 设置参数默认值,未传入参数时按照默认值
function f(x, y, z) {
  if (y === undefined) {
    y = 7
  }
  if (z === undefined) {
    z = 42
  }
  return x + y + z
}

console.log(f(1)) // 50
console.log(f(1, 8, 43)) // 52

 

重学ES6(三):函数和箭头函数

标签:箭头   console   设置   pre   参数   箭头函数   默认值   undefined   turn   

原文地址:https://www.cnblogs.com/xzweb/p/12271164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!