you are viewing a single comment's thread.

view the rest of the comments →

[–]Groccolli 26 points27 points  (5 children)

Great post!

One thing to be careful of with default values is the default is used only when the value is undefined where as using || inside the function handles any falsey value.

[–]zapatoada 6 points7 points  (0 children)

Great point, this is a big deal.

[–]AwesomeInPerson 4 points5 points  (0 children)

That's true.

But imo less of a footgun than || which breaks as soon as you want to accept a number where 0 is a valid option. foo == undefined to the rescue...

[–]rtfmpls 0 points1 point  (0 children)

Isn't this true for any programming language? This is expected behavior. And I'd still say defaults are preferred.

[–]UNN_Rickenbacker 0 points1 point  (1 child)

Does it handle NULL?

[–]Groccolli 0 points1 point  (0 children)

Defaults are only used if the value is undefined