Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Default Parameter Values in javascript

// Default Parameter Values in javascript
// Longhand:
function volume(l, w, h) {
    if (w === undefined)
      w = 3;
    if (h === undefined)
      h = 4;
    return l * w * h;
  }
console.log(volume(2)); //output: 24
  
// Shorthand:
volume_ = (l, w = 3, h = 4 ) => (l * w * h);
console.log(volume_(2)) //output: 24
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #Default #Parameter #Values #javascript
ADD COMMENT
Topic
Name
2+9 =