Skip to content

Instantly share code, notes, and snippets.

@jachin
Created February 22, 2012 21:53
Show Gist options
  • Save jachin/1887667 to your computer and use it in GitHub Desktop.
Save jachin/1887667 to your computer and use it in GitHub Desktop.
Default values for function arguments in javascript.
function foo ( red, blue ) {
// default value for red is true.
red = typeof red !== 'undefined' ? red : true;
// default value for blue is 55.
blue = typeof blue !== 'undefined' ? blue : 55;
console.log( red );
console.log( blue );
}
foo( );
foo( false );
foo( true, 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment