How to use function with parameters and default values in JavaScript ES6

2 Answers

0 votes
function f(x = 3, y = 8) {
    console.log(x + ' ' + y);
}

f();
f(1);
f(87, 99);



     
/*
run:
   
3 8
1 8
87 99
 
*/

 



answered Mar 8, 2020 by avibootz
0 votes
function f(x = 3, y = x) {
    console.log(x + ' ' + y);
}
 
f();
f(1);
f(87, 99);
 
 
 
      
/*
run:
    
3 3
1 1
87 99
  
*/

 



answered Mar 16, 2020 by avibootz
...