Skip to main content
CSS is fun and cool and I like it.
Snippet

Required Parameters for Functions in JavaScript

Ooo this is clever! I’m snagging this from David’s blog.

const isRequired = () => { throw new Error('param is required'); };

const hello = (name = isRequired()) => { console.log(`hello ${name}`) };

// These will throw errors
hello();
hello(undefined);

// These will not
hello(null);
hello('David');
Read article “Required Parameters for Functions in JavaScript”