Created
February 22, 2012 21:53
-
-
Save jachin/1887667 to your computer and use it in GitHub Desktop.
Default values for function arguments in javascript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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