Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  147] [ 1]  / answers: 1 / hits: 16096  / 9 Years ago, thu, october 8, 2015, 12:00:00

want to check null values. any() method returns null or array of matched result (actually there's a match() method inside which is returned).



$scope.isMobileBrowser = !isMobile.any() ? false : true;


If any() method returns null I want false to be assigned to $scope.isMobileBrowser variable, otherwise true. will the over mentioned snippet fail in any probable case? Is there any other more efficient workaround?



for more details of isMobile object:



var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};

More From » performance

 Answers
20

Empty string is also a falsy value.

If any() returns an empty string, !isMobile.any() ? false : true will return false, but you probably want true.



This means your code is incorrect for this case.



I'd just do something like isMobile.any() !== null.


[#64803] Monday, October 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alora

Total Points: 284
Total Questions: 99
Total Answers: 92

Location: Singapore
Member since Sat, Jul 25, 2020
4 Years ago
;