Unexpected Behavior When Using Default Parameter Values in JavaScript Arrow Functions - ES2023
I'm performance testing and I'm having a hard time understanding I've searched everywhere and can't find a clear answer... I'm attempting to set up I'm encountering an unexpected behavior with default parameter values in ES2023 arrow functions. I have the following code snippet: ```javascript const add = (a, b = 2) => a + b; console.log(add(3)); // Expected: 5 console.log(add(3, 4)); // Expected: 7 console.log(add(undefined, 4)); // Expected: 6 ``` The first two calls work as intended, but the third one returns `NaN` instead of `6`. I expected that passing `undefined` as the first argument would trigger the default value of `2` for `b`, but it seems like `b` is being assigned `4` instead. I also tried changing the arrow function to a regular function: ```javascript function add(a, b = 2) { return a + b; } console.log(add(3)); // Expected: 5 console.log(add(3, 4)); // Expected: 7 console.log(add(undefined, 4)); // Expected: 6 ``` In this case, it works correctly and returns `6`. This inconsistency is quite puzzling to me. Is there something specific about how arrow functions handle default parameters that I am missing? Any insights or workarounds would be greatly appreciated! The stack includes Javascript and several other technologies. Could this be a known issue? I'm developing on Windows 10 with Javascript. I recently upgraded to Javascript stable.