> 文章列表 > ES6 箭头函数的参数和返回值

ES6 箭头函数的参数和返回值

ES6 箭头函数的参数和返回值

1.4.2.1 参数问题

1.放入两个参数

const sum = (num1,num2) => {return num1 + num2 
}

2.放入一个参数,()可以省略

const power = num => {return num * num
}

1.4.2.2 函数内部

1.函数中代码块中有多行代码

const test = () =>{console.log("hello zzz")console.log("hello vue")
}

2.函数代码块中只有一行代码,可以省略return

// const mul = (num1,num2) => {
//   return num1 * num2
// }
const mul = (num1,num2) => num1* num2
// const log = () => {
//   console.log("log")
// }
const log = () => console.log("log")