Skip to content

Instantly share code, notes, and snippets.

@chrisblackwell
Created November 21, 2016 13:31
Show Gist options
  • Save chrisblackwell/d19d978882a44a0641365f35efd37204 to your computer and use it in GitHub Desktop.
Save chrisblackwell/d19d978882a44a0641365f35efd37204 to your computer and use it in GitHub Desktop.
JavaScript required parameters
const isRequired = () => { throw new Error('param is required'); };
const hello = (name = isRequired()) => { console.log(`hello ${name}`) };
// This will throw an error because no name is provided
hello();
// This will also throw an error
hello(undefined);
// These are good!
hello(null);
hello('David');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment