Javascript – Default values for function input parameters

A good example says it all.

function foo(a, b) {
  a = typeof a !== 'undefined' ? a : 42;
  b = typeof b !== 'undefined' ? b : 'default_b';
  
  // Do whatever you want
}

 

Done =)

Reference: StackOverflow – How do I make a default value for a parameter to a javascript function

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.