我正在玩ES6默认参数,我有一个奇怪的行为.
以下是该问题的一个简短示例:
function test(firstValue, secondValue=5){
console.log("firstValue: " + firstValue);
console.log("secondValue: " + secondValue);
console.log("----------")
}
test(2, secondValue = 3)
test(secondValue = 3)
Run Code Online (Sandbox Code Playgroud)
它的输出:
firstValue: 2
secondValue: 3
----------
firstValue: 3
secondValue: 5
----------
Run Code Online (Sandbox Code Playgroud)
在第二种情况下,我期待firstValue: undefined和secondValue: 3.这种行为是否正常.我错过了什么吗?