Testing for null, etc.
by john_s
HTML
<div id="output">
</div>
JavaScript
var memoize = function(getter) {
var undefined, value;
return function() {
if (value === undefined) {
value = getter.apply(this, arguments);
}
return value;
};
};
var isIos = memoize(function() {
//return !!navigator.userAgent.match(/(iPhone|iPod|iPad)/i);
return /'(iPhone|iPod|iPad)/i.test(navigator.userAgent);
});
var lines = [],
nullValue = null,
undefinedValue = undefined,
emptyValue = '',
zeroValue = 0;
lines.push('v == null, v is null: ' + (nullValue == null));
lines.push('v == null, v is undefined: ' + (undefinedValue == null));
lines.push('v == null, v is \'\': ' + (emptyValue == null));
lines.push('v == null, v is 0: ' + (zeroValue == null));
lines.push('check 1: ' + isIos());
lines.push('check 2: ' + isIos());
lines.push('check 3: ' + isIos());
$('#output').html(lines.join('<br />'));