const add = (x=5, y=10) => console.log(x+y);
After we run the transpiler on this code, here is what the output would look like:
"use strict";
var add = function add() {
var x = arguments.length <= 0 || arguments[0] === undefined ?
5 : arguments[0];
var y = arguments.length <= 1 || arguments[1] === undefined ?
10 : arguments[1];
return console.log(x + y);
};
I got this snippet from Learning react book. I have two question here
- Can arguments.length be negative?
- Does checking the second "||" condition be sufficient to check whether arguments[0] or arguments[1] is undefined?
arguments
out of bounds.