Parenthesis are required around your arrow function when using a default value.
// Correct approach for default values
var prev = (a = new Date()) => a;
// Incorrect approach
var prev = a = new Date() => a; // Nope. Where does the arrow function start?
var prev = a = (new Date()) => a; // Invalid parameter name right?
Why?
Because in var prev = a = new Date() => a;
the compiler thinks you are asking:
- Make
prev
equal the value a
which equals the value of an arrow function
with new Date()
as the parameter name? Error!
It's not explicit enough so the compiler doesn't like it. If you have defaults wrap them in parentheses.
Read more on MDN Default Params