Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active June 28, 2016 03:43
Show Gist options
  • Save joseluisq/df990b5638f71f18d969 to your computer and use it in GitHub Desktop.
Save joseluisq/df990b5638f71f18d969 to your computer and use it in GitHub Desktop.
How assign default value to a param for functions in Javascript
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