Re:Args.js – Optional and Default parameters for JavaScript
by simon_renoult on Monday January 13, 2014 @10:37AM
(#7051139)
Why using :
Over :
Coercion avoidance ?
[ Parent
| on HN ]
Re:Args.js – Optional and Default parameters for JavaScript
by dagw on Monday January 13, 2014 @11:12AM
(#7051362)
The second function sets bar to "default_value" if called with a falsy argument like 0 or an empty string.
Re:Args.js – Optional and Default parameters for JavaScript
by niyazpk on Monday January 13, 2014 @10:54AM
(#7051244)
Yes, the second option is better in most cases. I'd spend more time reading the first one to understand what is going on compared to the second option.
Keep in mind that you will have to go for the first option (or other better options) if you expect 'falsy' values to be passed as arguments.