You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is actually very different from setting a default value to bar. It is not supposed to work like it does in ES6. The syntax means that if only one argument is provided, then that argument is bar, and the default argument for foo is inserted at the beginning of the list of arguments. In other words:
So basically the use case for the syntax is when your optional argument is the first one, for example:
subtract(a = 0, b) = a - b
subtract(1, 2) == 1 - 2 == -1
subtract(2) == 0 - 2 == -2
It might be a bit more consistent if bar was filled to undefined if no arguments are given at all, as is the case normally, but I think implicit defaults are kind of a wart of JavaScript to begin with, so I'm somewhat ambivalent about "fixing" that.
For example this works fine:
But this breaks (with a match error):
Would also be quite nice if these examples compiled to ES6 default arguments.
The text was updated successfully, but these errors were encountered: