Created
January 29, 2014 21:44
-
-
Save klauskpm/8697832 to your computer and use it in GitHub Desktop.
Functions to know if the variable is defined and to set a default value if not.
This file contains 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 defaultIfUndefined(variable, value) { | |
return isUndefined(variable)?value:variable; | |
} | |
function isUndefined(variable) { | |
return typeof(variable)=='undefined'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment