This question tests your understanding of ES6 default parameters. A jar has 30 red and 50 green marbles. A function draw() takes two parameters and decreases the quantity of red and green marbles in the jar. First parameter, red
, has default value 1 and the second parameter, green
, defaults to 1 by ||
operator in the function body:
var jar = { red: 30, green: 50 };
function draw(red=1, green) {
green = green || 1;
jar.red -= red;
jar.green -= green;
}
The function draw() is called 3 times with different arguments followed by printing the values of jar.red and jar.green:
draw();
draw(0,2);
draw(2,0);
// Print object jar
console.log('red: ' + jar.red + ', green: '+ jar.green);
What will be printed above?