Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Default function parameters

The default func­tion para­me­ters in ES6, gives us the abil­ity to ini­tial­ize the func­tion argu­ments with default val­ues in case if they are undefined.

For exam­ple,

function mult(a, b) { b = typeof b !== 'undefined' ? b : 1; return a*b; } mult(5); // 5

It can be writ­ten as follows:

function multiply(a, b = 1) {
  return a*b;
mult(5); // 5

Default Para­me­ters