How can I make a utility helper function in JavaScript to check for existence of a variable to avoid the error Uncaught ReferenceError: testVar is not defined?
Below is what I am trying to do but failed!
/**
* Utility Helper Functions
*/
var Utility = {
/**
* Check if a variable is empty or not
* @param mixed value - variable to check if it is empty and exist
* @return Boolean - true/false if a variable is empty or not?
*/
isEmpty: function(value){
//return (value == null || value === '');
return (typeof value === 'undefined' || value === null);
},
}
// comment var test out so it will not exist for test
//var testVar = 'dgfd';
// Uncaught ReferenceError: testVar is not defined
alert(Utility.isEmpty(testVar));
window, but you can't do that for local variables.)