控制台登录javascript函数

时间:2017-09-20 15:12:38

标签: javascript function syntax-error

const getAverage = (numberOne, numberTwo) => {
    const average = (numberOne + numberTwo) / 2 ;
    console.log(average);
};

getAverage(365, 27);
// Output: 196

const getAverage = (numberOne, numberTwo) => {
    const average = (numberOne + numberTwo) / 2 ;
    return average;
};

getAverage(365, 27);
// Output:  SyntaxError: Identifier 'getAverage' has already been declared
at <anonymous>:1:1

为什么?

1 个答案:

答案 0 :(得分:0)

如果这些功能位于同一位置,那么您的问题是您使用相同的功能名称。

&#13;
&#13;
const getAverage = (numberOne, numberTwo) => {
	const average = (numberOne + numberTwo) / 2 ;
	console.log(average);
};

getAverage(365, 27);


const getAverage2 = (numberOne, numberTwo) => {
    const average = (numberOne + numberTwo) / 2 ;
    return average;
};

console.log(getAverage2(365, 27));
&#13;
&#13;
&#13;