According to MDN, this kind of check is done by JS internally in case of defaults
function go() {
return ":P"
}
function withDefaults(a, b = 5, c = b, d = go(), e = this,
f = arguments, g = this.value) {
return [a,b,c,d,e,f,g];
}
function withoutDefaults(a, b, c, d, e, f, g){
switch(arguments.length){
case 0:
a
case 1:
b = 5
case 2:
c = b
case 3:
d = go();
case 4:
e = this
case 5:
f = arguments
case 6:
g = this.value;
default:
}
return [a,b,c,d,e,f,g];
}
withDefaults.call({value:"=^_^="});
// [undefined, 5, 5, ":P", {value:"=^_^="}, arguments, "=^_^="]
withoutDefaults.call({value:"=^_^="});
// [undefined, 5, 5, ":P", {value:"=^_^="}, arguments, "=^_^="]
Now in your case, this is something like this -
case 0:
a
case 1:
b
case 2:
a = a
But when executing case 2, a
is still not defined, and hence it through in error scenario.
See details here https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/default_parameters