Created
November 21, 2016 13:31
-
-
Save chrisblackwell/d19d978882a44a0641365f35efd37204 to your computer and use it in GitHub Desktop.
JavaScript required parameters
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
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