Default value
Hurtak opened this issue · 3 comments
Hurtak commented
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';
}
}
bevacqua commented
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.
Hurtak commented
Why would you advice against typeof
check?
bevacqua commented
brevity