Last active
June 28, 2016 03:43
-
-
Save joseluisq/df990b5638f71f18d969 to your computer and use it in GitHub Desktop.
How assign default value to a param for functions in Javascript
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 myfunction(param) { | |
return (param === undefined) ? true : param; | |
} | |
/* Testing 'myfunction' in console.. | |
// Default value example | |
> myfunction(); | |
true | |
> myfunction('Hello world !'); | |
"Hello world !" | |
> myfunction(''); | |
"" | |
> myfunction(123456); | |
123456 | |
> myfunction(null); | |
null | |
> myfunction(false); | |
false | |
> myfunction(true); | |
true | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment