Created
June 3, 2020 13:48
-
-
Save bobdobbalina/0e9b96880dbce7b5f16f46396cbc8c0a to your computer and use it in GitHub Desktop.
Javascript: Parameter Validation
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 print = (num = isRequired()) => { console.log(`printing ${num}`) }; | |
print(2);//printing 2 | |
print()// error | |
print(null)//printing null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment