Default value
Hurtak opened this issue · comments
I don't think it's good to recommend using ||
for setting default value to variables. It's nice shortcut but it can cause trouble when valid input (0, false, '') is converted to default value. I would recommend mentioning explicitly these dangers in that chapter or add chapter about more safe default value assigning
function example(value) {
if (typeof value === 'undefined') {
value = 'defaultValue';
}
}
You can always add the recommendation in a pull request. I'd advice against the typeof
check, I prefer comparing against void 0
for brevity.
Why would you advice against typeof
check?
brevity