Quantcast
Channel: CSS-TricksCSS-Tricks
Viewing all articles
Browse latest Browse all 31

Required Parameters for Functions in JavaScript

$
0
0

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');

(more…)


Viewing all articles
Browse latest Browse all 31

Trending Articles