Be the first user to complete this post

  • 0
Add to List

Default function parameters

The default function parameters in ES6, gives us the ability to initialize the function arguments with default values in case if they are undefined. For example,

function mult(a, b) {
  b = typeof b !== 'undefined' ?  b : 1;
  return a*b;
mult(5); // 5
It can be written as follows:
function multiply(a, b = 1) {
  return a*b;
mult(5); // 5
Default Parameters

Also Read:

  1. position:fixed
  2. Error: can not find module 'underscore'
  3. Split a string in javascript when both comma and spaces are present
  4. Testing promise sequence using mocha, chai, chai-as-promised, sinon
  5. es6 iterators and iterables - creating custom iterators
  6. box-sizing
  7. Difference between async and defer attributes in script tags
  8. nodejs: generate uuid / guid