The first version of my code was:
function user_should_see_priority_items (user={}) {
// why double negative? we want the default to be that user can see priority items so if should_see_priority_items is not defined then it should see priority items
return user.should_see_priority_items !== false
}
I wrote a comment because I found the !== false confusing.
But after writing the comment I still found the code to be confusing. Then why not remove the reason for the comment?
const isNil = item => item === undefined || item === null
const useDefault = (_default, item) => isNil(item)
? _default
: item
function user_should_see_priority_items (user = {}) {
return useDefault(true, user.should_see_priority_items)
}
Always try to convert your comment into code