JSFiddle - React, Tailwind, and code Playground
by ChrisStanyon
JavaScript
function isset (accessor) {
try {
// Note we're seeing if the returned value of our function is not
// undefined
return typeof accessor() !== 'undefined'
} catch (e) {
// And we're able to catch the Error it would normally throw for
// referencing a property of undefined
return false
}
}
let rr6;
alert(isset(rr6)); //Should return true
rr6 = "Hello world";
alert(isset(rr6)); //Should return true
let rr7 = [];
rr7['t1'] = 72;
alert(isset(rr7)); //Should return true
alert(isset(rr7['t1'])); //Should return true
alert(isset(rr7['t2'])); //Should return false
alert(isset(rr8)); //Should return false
let $rr8;
$rr8 = "By World";
alert(isset($rr8));
//<input type="text" id="txtrr9" />
alert(isset($("#txtrr9").attr("id"))); // Should return true
alert(isset($("#txtrr9").data("guid"))); // Should return false