Essentially, if the value of query
is considered true (
typeof query != 'undefined' && query != null && query != 0 && query != false
), then the result of evaluating
$scope.allContacts.filter(createFilterFor(query))
will be returned. Otherwise, an empty array (
[]
) will be returned.
This approach ensures that an array will always be returned in any case.
If a check for query ?
is omitted and query
happens to be null
, there is a risk of encountering errors when running
$scope.allContacts.filter(createFilterFor(query))
. Therefore, this precaution is sometimes implemented for safety reasons.